You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@groovy.apache.org by Cédric Champeau <ce...@gmail.com> on 2018/05/23 06:25:38 UTC
Possible bug in AstBuilder Antlr4
Hi Daniel,
I think I have found a bug in the antlr4 AstBuilder class.
Add this line:
import groovy.transform.CompileStatic
before this one in a GString template:
https://github.com/melix/groovy-core/blob/d9656842908acb403599cf574f509aea2737be47/subprojects/groovy-groovydoc/src/main/resources/org/codehaus/groovy/tools/groovydoc/gstringTemplates/classLevel/classDocName.html#L27
And run GroovyDocToolTest. Some tests will fail with:
java.lang.ClassCastException: org.codehaus.groovy.ast.ImportNode cannot be
cast to org.codehaus.groovy.ast.stmt.Statement
at
org.apache.groovy.parser.antlr4.AstBuilder.visitBlockStatement(AstBuilder.java:4074)
at
java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at
java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at
java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at
java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at
java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
at
org.apache.groovy.parser.antlr4.AstBuilder.visitBlockStatements(AstBuilder.java:4058)
at
org.apache.groovy.parser.antlr4.AstBuilder.visitBlockStatementsOpt(AstBuilder.java:4045)
at
org.apache.groovy.parser.antlr4.AstBuilder.visitClosure(AstBuilder.java:3715)
at
org.apache.groovy.parser.antlr4.AstBuilder.visitClosurePrmrAlt(AstBuilder.java:3120)
at
org.apache.groovy.parser.antlr4.AstBuilder.visitClosurePrmrAlt(AstBuilder.java:356)
Re: Possible bug in AstBuilder Antlr4
Posted by Cédric Champeau <ce...@gmail.com>.
thanks!
Le mer. 23 mai 2018 à 09:48, Daniel.Sun <su...@apache.org> a écrit :
> It is fixed:
>
> https://github.com/apache/groovy/commit/a26c190f9a70b0c430004d80c56e37703c2edfe8
>
> Cheers,
> Daniel.Sun
>
>
>
> --
> Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html
>
Re: Possible bug in AstBuilder Antlr4
Posted by "Daniel.Sun" <su...@apache.org>.
It is fixed:
https://github.com/apache/groovy/commit/a26c190f9a70b0c430004d80c56e37703c2edfe8
Cheers,
Daniel.Sun
--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html
Re: Possible bug in AstBuilder Antlr4
Posted by "Daniel.Sun" <su...@apache.org>.
> I would have expected it to fail with a better error message in this case,
like "You're not allowed to use an import in a method body".
I agree with you :-)
Cheers,
Daniel.Sun
--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html
Re: Possible bug in AstBuilder Antlr4
Posted by Cédric Champeau <ce...@gmail.com>.
It cannot. However the GString templates look like scripts, which is why I
added an import in the first place. But then the builder fails with a
ClassCastException. I would have expected it to fail with a better error
message in this case, like "You're not allowed to use an import in a method
body".
Le mer. 23 mai 2018 à 08:34, Daniel.Sun <su...@apache.org> a écrit :
> Hi Cédric,
>
> `import` statement can appear in a block?
>
> Cheers,
> Daniel.Sun
>
>
>
> --
> Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html
>
Re: Possible bug in AstBuilder Antlr4
Posted by "Daniel.Sun" <su...@apache.org>.
As the error message shows, error occurred when parsing statements within a
block, but one of the statements is actually a `import` statement.
We should add some check to give friendly error message IMO.
Cheers,
Daniel.Sun
--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html
Re: Possible bug in AstBuilder Antlr4
Posted by "Daniel.Sun" <su...@apache.org>.
Hi Cédric,
`import` statement can appear in a block?
Cheers,
Daniel.Sun
--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html