File tree Expand file tree Collapse file tree 2 files changed +53
-3
lines changed
main/java/org/codehaus/groovy/classgen Expand file tree Collapse file tree 2 files changed +53
-3
lines changed Original file line number Diff line number Diff line change 133133import static org .codehaus .groovy .ast .tools .GeneralUtils .classX ;
134134import static org .codehaus .groovy .ast .tools .GeneralUtils .fieldX ;
135135import static org .codehaus .groovy .ast .tools .GeneralUtils .getSetterName ;
136+ import static org .codehaus .groovy .ast .tools .GeneralUtils .inSamePackage ;
136137import static org .codehaus .groovy .ast .tools .GeneralUtils .isOrImplements ;
137138import static org .codehaus .groovy .ast .tools .GeneralUtils .propX ;
138139import static org .codehaus .groovy .ast .tools .GeneralUtils .thisPropX ;
@@ -1109,9 +1110,10 @@ public void visitPropertyExpression(final PropertyExpression expression) {
11091110 }
11101111 } else {
11111112 fieldNode = classNode .getSuperClass ().getDeclaredField (name );
1112- // GROOVY-4497: do not visit super class field if it is private
1113- if (fieldNode != null && fieldNode .isPrivate ()) fieldNode = null ;
1114-
1113+ // GROOVY-4497, GROOVY-11764: do not visit super class field if it is private or package-private
1114+ if (fieldNode != null && (fieldNode .isPrivate () || !(fieldNode .isPublic () || fieldNode .isProtected () || inSamePackage (classNode , classNode .getSuperClass ())))) {
1115+ fieldNode = null ;
1116+ }
11151117 if (fieldNode == null ) {
11161118 visited = tryPropertyOfSuperClass (expression , name );
11171119 }
Original file line number Diff line number Diff line change 1+ /*
2+ * Licensed to the Apache Software Foundation (ASF) under one
3+ * or more contributor license agreements. See the NOTICE file
4+ * distributed with this work for additional information
5+ * regarding copyright ownership. The ASF licenses this file
6+ * to you under the Apache License, Version 2.0 (the
7+ * "License"); you may not use this file except in compliance
8+ * with the License. You may obtain a copy of the License at
9+ *
10+ * http://www.apache.org/licenses/LICENSE-2.0
11+ *
12+ * Unless required by applicable law or agreed to in writing,
13+ * software distributed under the License is distributed on an
14+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+ * KIND, either express or implied. See the License for the
16+ * specific language governing permissions and limitations
17+ * under the License.
18+ */
19+ package bugs
20+
21+ import org.junit.Test
22+
23+ final class Groovy11764 {
24+
25+ @Test
26+ void testReadFieldPropertyShadowing () {
27+ def shell = new GroovyShell ()
28+ shell. parse ''' package p
29+ class A {
30+ Number getValue() {
31+ 42
32+ }
33+ }
34+ class B extends A {
35+ @groovy.transform.PackageScope String value = 'xx'
36+ }
37+ '''
38+ shell. evaluate '''
39+ class C extends p.B {
40+ void test() {
41+ assert super.value == 42
42+ }
43+ }
44+
45+ new C().test()
46+ '''
47+ }
48+ }
You can’t perform that action at this time.
0 commit comments