Scott Murphy Heiberg created GROOVY-12621:
---------------------------------------------
Summary: STC still accepts some private superclass field accesses
under @TypeChecked that fail at run time
Key: GROOVY-12621
URL: https://issues.apache.org/jira/browse/GROOVY-12621
Project: Groovy
Issue Type: Bug
Affects Versions: 5.0.8, 4.0.33, 6.0.0
Reporter: Scott Murphy Heiberg
GROOVY-12610 makes the type checker reject property access to a private
instance field of a superclass when dynamic dispatch can never find it. Three
shapes are still accepted and fail with a MissingPropertyException.
Enum constant body (z, this.z and super.z all fail):
{code:groovy}
@groovy.transform.TypeChecked
enum E {
A { def n() { z } }
private String z = 'x'
}
E.A.n()
{code}
Write through super in a non-static inner subclass (compound assignment and
increment also fail):
{code:groovy}
@groovy.transform.TypeChecked
class Base {
private String z = 'x'
class Sub extends Base {
def m() { super.z = 'y' }
}
def t() { new Sub().m() }
}
new Base().t()
{code}
Receiver that is not an instance of the calling inner class:
{code:groovy}
@groovy.transform.TypeChecked
class Base {
private String z = 'x'
static class Sub extends Base {}
class Inner {
def m(Sub sub) { sub.z }
}
def t() { new Inner().m(new Sub()) }
}
new Base().t()
{code}
Actual: all three compile and then fail with MissingPropertyException: No such
property: z for class: E$1 (or Base$Sub).
Expected: compile errors "No such property: z for class: ...", as for the
shapes GROOVY-12610 covers. Under @CompileStatic all three keep compiling,
since static compilation accesses the field directly.
Cause: ClassNodeUtils.hasNoEnclosingInstance returned false for an enum
constant body, which is created in the enum's static initializer. The type
checker also did not take two run-time limits into account: there is no
enclosing-instance fallback for a write through super (GROOVY-11823), and the
fallback applies only when the receiver is an instance of the calling class.
The enum case is seen in 4.0.33, 5.0.8 and 6.0.0.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)