[ https://issues.apache.org/jira/browse/GROOVY-10152?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17418184#comment-17418184 ]
Christopher Smith commented on GROOVY-10152: -------------------------------------------- The _meaning_ is erroneous; the actual code says {{ctx, tr.value}}, but the correct code was {{[ctx, tr.value]}}. Nevertheless, {{ctx, tr.value}} _should_ be a valid comma expression of type {{String}}. > Parrot can't parse closure > -------------------------- > > Key: GROOVY-10152 > URL: https://issues.apache.org/jira/browse/GROOVY-10152 > Project: Groovy > Issue Type: Bug > Components: parser-antlr4 > Affects Versions: 3.0.8 > Reporter: Christopher Smith > Priority: Minor > > I have this "cleanup" method in an ETL project. The intent is to call a > static method returning {{Try<String>}} that attempts to normalize a phone > number, then check whether we had an error processing any of them; if so, > return a failure, but if success, replace the existing phone numbers with the > normalized ones and return the record. > {code:groovy} > static Try<IdentityRecord> normalizePhones(IdentityRecord record) { > Map<String, Try<String>> normalized = record.phones.collectEntries { > ctx, number -> > [ctx, PhoneRules.normalize(number)] > } > return normalized.entrySet().stream() > .filter { it.value.failure } > .findFirst() > .map { Try.failure(new ValidationException("${it.key}: > ${it.value.cause.message}")) } > .orElseGet { > record.phones = normalized.collectEntries { ctx, tr -> ctx, > tr.value } > Try.success(record) > } > } > {code} > Parrot is giving me a generic parse error on the closure for the > {{orElseGet}} call, and I can't figure out why. Commenting out the assignment > statement removes the error (but of course prevents the intended > modification). Adding {{_ ->}} does not change the error, and neither does > inserting semicolons in various places. > {code} > Groovy:Unexpected input: '{' > {code} > Update: It appears that my attempted more-minimal workaround still triggers > the problem: > {code:groovy} > static void groovy10152(IdentityRecord record, Map<String, String> > normalized) { > normalized.collectEntries { ctx, tr -> ctx, tr.value } > } > {code} > results in the same error at the opening of the closure: > {code} > Groovy:Unexpected input: '{' > {code} > (And now, finally, I am realizing that what's confusing it is the comma > expression at the end. While this *should* be legal syntax and result in a > type-checking error, it's causing a parser error instead. Even in this case, > though, the grammar appears to be causing the error to be reported at a > substantially incorrect location. Marking the priority down since fixing the > semantic error also fixes the parser error.) -- This message was sent by Atlassian Jira (v8.3.4#803005)