[
https://issues.apache.org/jira/browse/GROOVY-12720?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Scott Murphy Heiberg updated GROOVY-12720:
------------------------------------------
Description:
A script may declare its own no-argument {{run()}}:
{{ModuleNode.createStatementsClass}} keeps it instead of generating one, and
copies its annotations to the script class so that, for example,
{{@CompileStatic}} on {{run()}} applies to the whole class. Every annotation is
copied, including {{@Override}}, whose only target is METHOD:
{code:groovy}
class PriceRules { int quotes = 0 }
@Override
Object run() {
println new PriceRules().quotes
null
}
{code}
Expected: compiles and runs; the method does override
{{groovy.lang.Script#run()}}. Actual, on 6.0.0 and master:
{noformat}
script.groovy: 5: Annotation @java.lang.Override is not allowed on element TYPE
{noformat}
The same script with {{@Deprecated}} compiles, and {{@Override}} on any other
script method is checked as usual ("does not override method from its
superclass").
Proposed fix: when the method's annotations are copied to the class, leave
{{@Override}} out; it stays on the method, where it is correct. The other
annotations keep moving to the class as before.
Found while scoring Groovy 6.0.0 code written by a language model: told that
the file is compiled with static type checking, it declared the script's
{{run()}} with {{@Override}} and {{@TypeChecked}}, and was given an error about
an element it had not annotated.
was:
A script may declare its own no-argument {{run()}}:
{{ModuleNode.createStatementsClass}} keeps it instead of generating one, and
copies its annotations to the script class so that, for example,
{{@CompileStatic}} on {{run()}} applies to the whole class. Every annotation is
copied, including {{@Override}}, whose only target is METHOD:
{code:groovy}
class PriceRules { int quotes = 0 }
@Override
Object run() {
println new PriceRules().quotes
null
}
{code}
Expected: compiles and runs; the method does override
{{groovy.lang.Script#run()}}. Actual, on 6.0.0 and master:
{noformat}
script.groovy: 5: Annotation @java.lang.Override is not allowed on element TYPE
{noformat}
The same script with {{@Deprecated}} compiles, and {{@Override}} on any other
script method is checked as usual ("does not override method from its
superclass").
Proposed fix: when the method's annotations are copied to the class, leave
{{@Override}} out; it stays on the method, where it is correct. The other
annotations keep moving to the class as before.
Found while scoring Groovy 6.0.0 code written by a language model: told that
the file is compiled with static type checking, it wrote {{@Override
@TypeChecked Object run() { ... }}} and was given an error about an element it
had not annotated.
> Script: @Override on a script's own run() method is copied to the script
> class and rejected ("not allowed on element TYPE")
> ---------------------------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-12720
> URL: https://issues.apache.org/jira/browse/GROOVY-12720
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 6.0.0
> Reporter: Scott Murphy Heiberg
> Priority: Major
>
> A script may declare its own no-argument {{run()}}:
> {{ModuleNode.createStatementsClass}} keeps it instead of generating one, and
> copies its annotations to the script class so that, for example,
> {{@CompileStatic}} on {{run()}} applies to the whole class. Every annotation
> is copied, including {{@Override}}, whose only target is METHOD:
> {code:groovy}
> class PriceRules { int quotes = 0 }
> @Override
> Object run() {
> println new PriceRules().quotes
> null
> }
> {code}
> Expected: compiles and runs; the method does override
> {{groovy.lang.Script#run()}}. Actual, on 6.0.0 and master:
> {noformat}
> script.groovy: 5: Annotation @java.lang.Override is not allowed on element
> TYPE
> {noformat}
> The same script with {{@Deprecated}} compiles, and {{@Override}} on any other
> script method is checked as usual ("does not override method from its
> superclass").
> Proposed fix: when the method's annotations are copied to the class, leave
> {{@Override}} out; it stays on the method, where it is correct. The other
> annotations keep moving to the class as before.
> Found while scoring Groovy 6.0.0 code written by a language model: told that
> the file is compiled with static type checking, it declared the script's
> {{run()}} with {{@Override}} and {{@TypeChecked}}, and was given an error
> about an element it had not annotated.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)