paulk-asert commented on PR #2996: URL: https://github.com/apache/groovy/pull/2996#issuecomment-6392545704
Thanks Daniel. 1. Mixed forms are in testPrecedenceAndAssociativity (a ?? b ?: c, a ?? b ?? c, a ?? false || true, 0 ?? 1 ? 'yes' : 'no'), and a ?: b ?? c, which parses as a ?: (b ?? c), is now in the user guide example. ?? shares the precedence of the ternary and Elvis operators and is right-associative, so 0 ?? 1 ? 'yes' : 'no' is 0 ?? (1 ? 'yes' : 'no'). That differs from C#, JavaScript and Swift, where ?? binds more tightly than the ternary, so the guide points it out and suggests parentheses when combining them. 2. A primitive left-hand side never evaluates the right-hand side. That was already tested for ??, and testPrimitiveTargetNeverAssigned now covers ??= on a primitive local and a primitive field, dynamically and under @CompileStatic. I've added "Null-coalescing operator" and "Null-coalescing assignment operator" sections to core-operators.adoc next to the Elvis sections, and added ?? and ??= to the precedence table. 3. testInferredType covers String and Integer targets under @CompileStatic. An int target from an Integer left-hand side and the inferred type of a mixed String/Integer expression also behave as expected. 4. Yes, the two-argument constructor keeps Elvis semantics, so existing AST code is unaffected. 5. testNullOnlyFallback asserts that 0, false, '', [] and [:] stay on the left-hand side, and testAssignOnlyWhenNull does the same for ??=. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
