[
https://issues.apache.org/jira/browse/GROOVY-10355?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18105775#comment-18105775
]
ASF GitHub Bot commented on GROOVY-10355:
-----------------------------------------
paulk-asert commented on code in PR #2817:
URL: https://github.com/apache/groovy/pull/2817#discussion_r3810065599
##########
src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java:
##########
@@ -5034,6 +5256,22 @@ public List<DeclarationExpression>
getDeclarationExpressions() {
private static final String PACKAGE_INFO = "package-info";
private static final String PACKAGE_INFO_FILE_NAME = PACKAGE_INFO +
".groovy";
+ /**
+ * Marks a cast whose type is a bare (possibly qualified) name and whose
operand shape
+ * could equally be read as an operator continuation of a parenthesized
value expression,
+ * so that later resolution failures can explain the ambiguity
(GROOVY-10355).
+ */
+ public static final String AMBIGUOUS_BARE_NAME_CAST =
"_AMBIGUOUS_BARE_NAME_CAST";
Review Comment:
Inverted the relationship.
> 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: GROOVY-10355-Assessment.pdf, 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)