groovy
  1. groovy
  2. GROOVY-2942

switch-case, blocks and closures

    Details

    • Type: Bug Bug
    • Status: Open Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.6-beta-1
    • Fix Version/s: 4.0
    • Component/s: None
    • Labels:
      None
    • Testcase included:
      yes
    • Number of attachments :
      1

      Description

      Please look a the attached file. I think it reveals a couple of problems with the Groovy syntax parser and Groovy's runtime behaviour.

      However, I don't know if the spec makes any restrictions on the placement of curly braces.

        Activity

        Hide
        blackdrag blackdrag added a comment -

        that

        		case 'return labelled closure': // compiles (should it?)
        
        			return
        
        			label: { // either unreachable or a 'labelled' closure
        
        				x ->
        
        				condition + ': was here'
        
        			}
        
        			break

        compiles is ok, it is still a closure, but the place it is defined is labeled... well.. something we do not need, but it is more complicated to forbid that.

        as for

        			{
        
        				x ->
        
        				println condition + ': was here'
        
        			}.call(condition)
        
        			break

        I am not sure why this does not compile... probably missing whitespace eating...

        None of these issues are special to switch-case, they should happen like this anywhere in the code.

        Show
        blackdrag blackdrag added a comment - that case ' return labelled closure': // compiles (should it?) return label: { // either unreachable or a 'labelled' closure x -> condition + ': was here' } break compiles is ok, it is still a closure, but the place it is defined is labeled... well.. something we do not need, but it is more complicated to forbid that. as for { x -> println condition + ': was here' }.call(condition) break I am not sure why this does not compile... probably missing whitespace eating... None of these issues are special to switch-case, they should happen like this anywhere in the code.
        Hide
        blackdrag blackdrag added a comment -

        setting 4.0 as version for the grammar change

        Show
        blackdrag blackdrag added a comment - setting 4.0 as version for the grammar change

          People

          • Assignee:
            blackdrag blackdrag
            Reporter:
            Alexander Veit
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: