You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2020/10/24 01:53:33 UTC

[groovy] 01/01: GROOVY-9093: SC: add compile-time error for inaccessible field or getter

This is an automated email from the ASF dual-hosted git repository.

emilles pushed a commit to branch GROOVY-9093
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit dbf881e2dd46c2c8160f78ef1d24dcc76acf0edd
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Fri Oct 23 20:53:03 2020 -0500

    GROOVY-9093: SC: add compile-time error for inaccessible field or getter
---
 .../codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java   | 5 +++++
 src/test/groovy/bugs/Groovy7165.groovy                               | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
index 8ff1407..27fd08b 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
@@ -473,6 +473,11 @@ public class StaticTypesCallSiteWriter extends CallSiteWriter {
         if (makeGetPrivateFieldWithBridgeMethod(receiver, receiverType, propertyName, safe, implicitThis)) return;
         if (makeGetField(receiver, receiverType, propertyName, safe, implicitThis)) return;
 
+        boolean isScriptVariable = (receiverType.isScript() && receiver instanceof VariableExpression && ((VariableExpression) receiver).getAccessedVariable() == null);
+        if (!isScriptVariable && controller.getClassNode().getOuterClass() == null) { // inner class still needs dynamic property sequence
+            addPropertyAccessError(receiver, propertyName, receiverType);
+        }
+
         MethodCallExpression call = callX(receiver, "getProperty", args(constX(propertyName)));
         call.setImplicitThis(implicitThis);
         call.setMethodTarget(GROOVYOBJECT_GETPROPERTY_METHOD);
diff --git a/src/test/groovy/bugs/Groovy7165.groovy b/src/test/groovy/bugs/Groovy7165.groovy
index 4ee9a12..5880057 100644
--- a/src/test/groovy/bugs/Groovy7165.groovy
+++ b/src/test/groovy/bugs/Groovy7165.groovy
@@ -74,7 +74,7 @@ final class Groovy7165 {
             new B().test()
         '''
 
-        assert err =~ /MissingPropertyException: No such property: CONST for class: B/
+        assert err =~ /Access to B#CONST is forbidden/
     }
 
     @Test