File tree 4 files changed +44
-0
lines changed
org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc
org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc
org.codehaus.groovy40/src/org/codehaus/groovy/transform/stc
base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform
4 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -2671,6 +2671,25 @@ public void testTypeChecked9844() {
2671
2671
runConformTest (sources , "[key:val][key:val]" );
2672
2672
}
2673
2673
2674
+ @ Test
2675
+ public void testTypeChecked9854 () {
2676
+ //@formatter:off
2677
+ String [] sources = {
2678
+ "Main.groovy" ,
2679
+ "@groovy.transform.TypeChecked\n " +
2680
+ "void test() {\n " +
2681
+ " switch (42) {\n " +
2682
+ " case { it > 1 }:\n " +
2683
+ " print 'works'\n " +
2684
+ " }\n " +
2685
+ "}\n " +
2686
+ "test()\n " ,
2687
+ };
2688
+ //@formatter:on
2689
+
2690
+ runConformTest (sources , "works" );
2691
+ }
2692
+
2674
2693
@ Test (expected = AssertionError .class )
2675
2694
public void testTypeChecked9873 () {
2676
2695
Map <String , String > options = getCompilerOptions ();
Original file line number Diff line number Diff line change @@ -4719,7 +4719,20 @@ public BinaryExpression findInstanceOfNotReturnExpression(IfStatement ifElse) {
4719
4719
public void visitSwitch (final SwitchStatement statement ) {
4720
4720
Map <VariableExpression , List <ClassNode >> oldTracker = pushAssignmentTracking ();
4721
4721
try {
4722
+ /* GRECLIPSE edit -- GROOVY-9854
4722
4723
super.visitSwitch(statement);
4724
+ */
4725
+ visitStatement (statement );
4726
+ statement .getExpression ().visit (this );
4727
+ ClassNode type = getType (statement .getExpression ());
4728
+ for (CaseStatement caseStatement : statement .getCaseStatements ()) {
4729
+ if (caseStatement .getExpression () instanceof ClosureExpression ) // propagate the type
4730
+ caseStatement .getExpression ().putNodeMetaData (StaticTypesMarker .CLOSURE_ARGUMENTS , new ClassNode []{type });
4731
+
4732
+ caseStatement .visit (this );
4733
+ }
4734
+ statement .getDefaultStatement ().visit (this );
4735
+ // GRECLIPSE end
4723
4736
} finally {
4724
4737
popAssignmentTracking (oldTracker );
4725
4738
}
Original file line number Diff line number Diff line change @@ -4495,6 +4495,12 @@ protected void afterSwitchConditionExpressionVisited(final SwitchStatement state
4495
4495
4496
4496
@ Override
4497
4497
public void visitCaseStatement (final CaseStatement statement ) {
4498
+ Expression expression = statement .getExpression ();
4499
+ if (expression instanceof ClosureExpression ) { // GROOVY-9854: propagate the switch type
4500
+ SwitchStatement switchStatement = typeCheckingContext .getEnclosingSwitchStatement ();
4501
+ ClassNode inf = switchStatement .getExpression ().getNodeMetaData (TYPE );
4502
+ expression .putNodeMetaData (CLOSURE_ARGUMENTS , new ClassNode []{inf });
4503
+ }
4498
4504
super .visitCaseStatement (statement );
4499
4505
restoreTypeBeforeConditional ();
4500
4506
}
Original file line number Diff line number Diff line change @@ -4122,6 +4122,12 @@ protected void afterSwitchConditionExpressionVisited(final SwitchStatement state
4122
4122
4123
4123
@ Override
4124
4124
public void visitCaseStatement (final CaseStatement statement ) {
4125
+ Expression expression = statement .getExpression ();
4126
+ if (expression instanceof ClosureExpression ) { // GROOVY-9854: propagate the switch type
4127
+ SwitchStatement switchStatement = typeCheckingContext .getEnclosingSwitchStatement ();
4128
+ ClassNode inf = switchStatement .getExpression ().getNodeMetaData (TYPE );
4129
+ expression .putNodeMetaData (CLOSURE_ARGUMENTS , new ClassNode []{inf });
4130
+ }
4125
4131
super .visitCaseStatement (statement );
4126
4132
restoreTypeBeforeConditional ();
4127
4133
}
You can’t perform that action at this time.
0 commit comments