[
https://issues.apache.org/jira/browse/GROOVY-12514?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Scott Murphy Heiberg updated GROOVY-12514:
------------------------------------------
Description:
{{N.this}} inside class {{N}} is {{this}}. The type checker rejects it when
{{N}} is a nested class:
{code:groovy}
@groovy.transform.CompileStatic
class Box {
static class N {
String id = 'n'
String test() { N.this.id }
}
}
new Box.N().test()
{code}
{code}
[Static type checking] - No such property: this for Class or static property
for class: Box$N
{code}
Dynamic Groovy returns {{n}}, and javac accepts the same code ({{return
N.this.id;}}). The same error is reported under {{@TypeChecked}}, for an inner
(non-static) class {{N}}, for {{N.this.pm()}} and {{N.this.id = 'w'}}, and
inside a closure or lambda in {{N}}. {{N.this}} inside an anonymous class
created in {{N}} already works, because {{N}} is an outer class there.
For a top-level class the compiler rejects it in every mode, dynamic Groovy
included:
{code:groovy}
class Top {
String id = 't'
String test() { Top.this.id }
}
new Top().test()
{code}
{code}
The usage of 'Class.this' and 'Class.super' is only allowed in nested/inner
classes.
{code}
javac accepts it and prints {{t}}. Seen in 5.0.8, 6.0.0 and master.
{{C.super.m()}} naming the current class has the same problems. {{N.super.m()}}
inside a nested class {{N}} fails under {{@CompileStatic}} with "No such
property: super for Class or static property for class: Box$N", while dynamic
Groovy calls the superclass method. {{Top.super.m()}} in a top-level class
fails in every mode with the message above, while javac accepts it and calls
the superclass method (JLS 15.12.1 allows {{T.super}} when {{T}} is the current
class).
Expected: {{C.this}} and {{C.super}} naming the class that contains the code
mean {{this}} and {{super}}, in every mode, except in a static context, where
they stay an error.
was:
{{N.this}} inside class {{N}} is {{this}}. The type checker rejects it when
{{N}} is a nested class:
{code:groovy}
@groovy.transform.CompileStatic
class Box {
static class N {
String id = 'n'
String test() { N.this.id }
}
}
new Box.N().test()
{code}
{code}
[Static type checking] - No such property: this for Class or static property
for class: Box$N
{code}
Dynamic Groovy returns {{n}}, and javac accepts the same code ({{return
N.this.id;}}). The same error is reported under {{@TypeChecked}}, for an inner
(non-static) class {{N}}, for {{N.this.pm()}} and {{N.this.id = 'w'}}, and
inside a closure or lambda in {{N}}. {{N.this}} inside an anonymous class
created in {{N}} already works, because {{N}} is an outer class there.
For a top-level class the compiler rejects it in every mode, dynamic Groovy
included:
{code:groovy}
class Top {
String id = 't'
String test() { Top.this.id }
}
new Top().test()
{code}
{code}
The usage of 'Class.this' and 'Class.super' is only allowed in nested/inner
classes.
{code}
javac accepts it and prints {{t}}. Seen in 5.0.8, 6.0.0 and master.
Expected: {{C.this}} naming the class that contains the code means {{this}}, in
every mode, except in a static context, where it stays an error.
Summary: Qualified this or super naming the current class (N.this,
N.super inside N) is rejected (was: Qualified this naming the current class
(N.this inside N) is rejected)
> Qualified this or super naming the current class (N.this, N.super inside N)
> is rejected
> ---------------------------------------------------------------------------------------
>
> Key: GROOVY-12514
> URL: https://issues.apache.org/jira/browse/GROOVY-12514
> Project: Groovy
> Issue Type: Bug
> Components: Compiler, Static Type Checker
> Affects Versions: 6.0.0
> Reporter: Scott Murphy Heiberg
> Priority: Major
>
> {{N.this}} inside class {{N}} is {{this}}. The type checker rejects it when
> {{N}} is a nested class:
> {code:groovy}
> @groovy.transform.CompileStatic
> class Box {
> static class N {
> String id = 'n'
> String test() { N.this.id }
> }
> }
> new Box.N().test()
> {code}
> {code}
> [Static type checking] - No such property: this for Class or static property
> for class: Box$N
> {code}
> Dynamic Groovy returns {{n}}, and javac accepts the same code ({{return
> N.this.id;}}). The same error is reported under {{@TypeChecked}}, for an
> inner (non-static) class {{N}}, for {{N.this.pm()}} and {{N.this.id = 'w'}},
> and inside a closure or lambda in {{N}}. {{N.this}} inside an anonymous class
> created in {{N}} already works, because {{N}} is an outer class there.
> For a top-level class the compiler rejects it in every mode, dynamic Groovy
> included:
> {code:groovy}
> class Top {
> String id = 't'
> String test() { Top.this.id }
> }
> new Top().test()
> {code}
> {code}
> The usage of 'Class.this' and 'Class.super' is only allowed in nested/inner
> classes.
> {code}
> javac accepts it and prints {{t}}. Seen in 5.0.8, 6.0.0 and master.
> {{C.super.m()}} naming the current class has the same problems.
> {{N.super.m()}} inside a nested class {{N}} fails under {{@CompileStatic}}
> with "No such property: super for Class or static property for class: Box$N",
> while dynamic Groovy calls the superclass method. {{Top.super.m()}} in a
> top-level class fails in every mode with the message above, while javac
> accepts it and calls the superclass method (JLS 15.12.1 allows {{T.super}}
> when {{T}} is the current class).
> Expected: {{C.this}} and {{C.super}} naming the class that contains the code
> mean {{this}} and {{super}}, in every mode, except in a static context, where
> they stay an error.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)