-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GROOVY-8283: SC: field hides getter of super class
- Loading branch information
1 parent
a69e055
commit 9819280
Showing
2 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ final class Groovy8283 { | |
A getFoo() { return foo } | ||
} | ||
class D extends C { | ||
protected B foo = new B() // hides A#foo; should hide A#getFoo in subclasses | ||
protected B foo = new B() | ||
} | ||
''' | ||
assertScript shell, '''import p.* | ||
|
@@ -56,6 +56,22 @@ final class Groovy8283 { | |
new E().test() | ||
assert new E().foo.class == A // not the field from this perspective | ||
''' | ||
} | ||
|
||
@Test | ||
void testReadFieldPropertyShadowing2() { | ||
def shell = new GroovyShell() | ||
shell.parse '''package p | ||
class A {} | ||
class B {} | ||
class C { | ||
protected A foo = new A() | ||
A getFoo() { return foo } | ||
} | ||
class D extends C { | ||
protected B foo = new B() | ||
} | ||
''' | ||
assertScript shell, '''import p.* | ||
class E extends D { | ||
@groovy.transform.ASTTest(phase=org.codehaus.groovy.control.CompilePhase.INSTRUCTION_SELECTION, value={ | ||
|
@@ -102,6 +118,42 @@ final class Groovy8283 { | |
''' | ||
} | ||
|
||
@Test | ||
void testReadFieldPropertyShadowing3() { | ||
def shell = GroovyShell.withConfig { | ||
ast(groovy.transform.CompileStatic) | ||
} | ||
shell.parse '''package p | ||
class A {} | ||
class B {} | ||
class C { | ||
protected A foo = new A() | ||
A getFoo() { return foo } | ||
} | ||
class D extends C { | ||
protected B foo = new B() | ||
} | ||
''' | ||
assertScript shell, '''import p.* | ||
class E extends D { | ||
void test() { | ||
assert foo.class == B | ||
assert this.foo.class == B | ||
assert [email protected] == B | ||
assert this.getFoo().getClass() == A | ||
def that = new E() | ||
assert that.foo.class == B | ||
assert [email protected] == B | ||
assert that.getFoo().getClass() == A | ||
} | ||
} | ||
new E().test() | ||
assert new E().foo.class == A // not the field from this perspective | ||
''' | ||
} | ||
|
||
@Test | ||
void testWriteFieldPropertyShadowing() { | ||
def shell = new GroovyShell() | ||
|