[
https://issues.apache.org/jira/browse/GROOVY-10355?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18105711#comment-18105711
]
ASF GitHub Bot commented on GROOVY-10355:
-----------------------------------------
paulk-asert opened a new pull request, #2817:
URL: https://github.com/apache/groovy/pull/2817
… x (design sketch)
A parenthesized bare name whose final segment starts lowercase is by
convention a value, not a class, so a cast mis-parse of the ambiguous shapes is
rebuilt in AstBuilder as the binary expression the syntax visually suggests,
preserving textual left-to-right grouping across precedence levels. The
binary-only keywords in/as captured as cast operand identifiers are restored to
their relational reading for any capitalization. Unresolvable bare-name cast
types now carry a hint explaining the ambiguity and the ((name)) workaround.
The grammar is unchanged: a predicate-gated castExprAlt is not viable
because adaptive prediction under the me.sunlan antlr4 fork only consults
semantic predicates when a decision conflict is registered, which this decision
never produces, so the predicate would only fire as a parse-time
FailedPredicateException.
> Compiler interpret variable name as class name when in parentheses.
> --------------------------------------------------------------------
>
> Key: GROOVY-10355
> URL: https://issues.apache.org/jira/browse/GROOVY-10355
> Project: Groovy
> Issue Type: Bug
> Components: parser-antlr4
> Affects Versions: 3.0.0, 4.0.0, 5.0.0
> Environment: JDK 11.0.12
> Reporter: Olof Asbrink
> Priority: Major
> Attachments: screenshot-1.png, screenshot-2.png
>
>
> This behavior seems unexpected:
> {code:java}
> String b = "B"
> System.out.println("A" + (b) + "C")
> {code}
> Throws this exception:
> {code:java}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup
> failed:
> /tmp/repo1.gm: 2: unable to resolve class b
> @ line 2, column 26.
> System.out.println("A" + (b) + "C")
> ^{code}
> However these examples work:
> {code:java}
> String b = "B"
> System.out.println("A" + b + "C")
> {code}
> and
> {code:java}
> String b = "B"
> System.out.println("A" + (b))
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)