Details
-
Type:
Improvement
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 1.8.1, 1.9-beta-1, 1.7.11
-
Component/s: None
-
Labels:None
-
Number of attachments :
Description
It seems like Groovy should be able to handle "Case 5" below,
but instead it reports a compile-time error.
//----------------------- // Case 1: OK //----------------------- bar = 0 ? "moo" : "cow" //----------------------- // Case 2: OK //----------------------- bar = 0 ? "moo" : "cow" //----------------------- // Case 3: OK //----------------------- bar = 0 ? "moo" : "cow" //----------------------- // Case 4: OK //----------------------- bar = 0 ? "moo" : "cow" //--------------------------------------------------- // Case 5: ERROR. // // Compiler says: // expecting ':', found '<newline>' //--------------------------------------------------- bar = 0 ? "moo" : "cow" //----------------------------------------------------- // Case 6: OK // // Groovy cannot figure out that this is a // valid ternary without the help of the '\' // line continuation escape. How come? // //----------------------------------------------------- bar = 0 ? "moo" \ : "cow"
Issue Links
- is duplicated by
-
GROOVY-4464
Loosen white space restrictions
-
the general rule for Groovy is to use the operator at the end of the line or use backslash to break the line over. This applies to most operators, including for example +