@@ -4029,6 +4029,7 @@ public void visitIfElse(final IfStatement ifElse) {
4029
4029
}
4030
4030
}
4031
4031
4032
+ @ Deprecated
4032
4033
protected void visitInstanceofNot (final BinaryExpression be ) {
4033
4034
BlockStatement currentBlock = typeCheckingContext .enclosingBlocks .getFirst ();
4034
4035
assert currentBlock != null ;
@@ -4037,13 +4038,14 @@ protected void visitInstanceofNot(final BinaryExpression be) {
4037
4038
} else {
4038
4039
// saving type of variables to restoring them after returning from block
4039
4040
Map <VariableExpression , List <ClassNode >> oldTracker = pushAssignmentTracking ();
4040
- getTypeCheckingContext () .pushTemporaryTypeInfo ();
4041
+ typeCheckingContext .pushTemporaryTypeInfo ();
4041
4042
typeCheckingContext .blockStatements2Types .put (currentBlock , oldTracker );
4042
4043
}
4043
4044
pushInstanceOfTypeInfo (be .getLeftExpression (), be .getRightExpression ());
4044
4045
}
4045
4046
4046
4047
@ Override
4048
+ @ Deprecated
4047
4049
public void visitBlockStatement (final BlockStatement block ) {
4048
4050
if (block != null ) {
4049
4051
typeCheckingContext .enclosingBlocks .addFirst (block );
@@ -4054,12 +4056,13 @@ public void visitBlockStatement(final BlockStatement block) {
4054
4056
}
4055
4057
}
4056
4058
4059
+ @ Deprecated
4057
4060
public void visitClosingBlock (final BlockStatement block ) {
4058
- BlockStatement peekBlock = typeCheckingContext .enclosingBlocks .removeFirst ();
4059
- boolean found = typeCheckingContext .blockStatements2Types .containsKey (peekBlock );
4061
+ BlockStatement theBlock = typeCheckingContext .enclosingBlocks .pop ();
4062
+ boolean found = typeCheckingContext .blockStatements2Types .containsKey (theBlock );
4060
4063
if (found ) {
4061
- Map <VariableExpression , List <ClassNode >> oldTracker = typeCheckingContext .blockStatements2Types .remove (peekBlock );
4062
- getTypeCheckingContext () .popTemporaryTypeInfo ();
4064
+ Map <VariableExpression , List <ClassNode >> oldTracker = typeCheckingContext .blockStatements2Types .remove (theBlock );
4065
+ typeCheckingContext .popTemporaryTypeInfo ();
4063
4066
popAssignmentTracking (oldTracker );
4064
4067
}
4065
4068
}
@@ -4075,6 +4078,7 @@ public void visitClosingBlock(final BlockStatement block) {
4075
4078
* Return expression , which contains instanceOf (without not)
4076
4079
* Return null, if not found
4077
4080
*/
4081
+ @ Deprecated
4078
4082
protected BinaryExpression findInstanceOfNotReturnExpression (final IfStatement ifElse ) {
4079
4083
Statement elseBlock = ifElse .getElseBlock ();
4080
4084
if (!(elseBlock instanceof EmptyStatement )) {
@@ -4111,6 +4115,7 @@ protected BinaryExpression findInstanceOfNotReturnExpression(final IfStatement i
4111
4115
* Return expression , which contains instanceOf (without not)
4112
4116
* Return null, if not found
4113
4117
*/
4118
+ @ Deprecated
4114
4119
protected BinaryExpression findNotInstanceOfReturnExpression (final IfStatement ifElse ) {
4115
4120
Statement elseBlock = ifElse .getElseBlock ();
4116
4121
if (!(elseBlock instanceof EmptyStatement )) {
@@ -4186,13 +4191,15 @@ private void restoreTypeBeforeConditional() {
4186
4191
4187
4192
protected Map <VariableExpression , ClassNode > popAssignmentTracking (final Map <VariableExpression , List <ClassNode >> oldTracker ) {
4188
4193
Map <VariableExpression , ClassNode > assignments = new HashMap <>();
4189
- typeCheckingContext .ifElseForWhileAssignmentTracker .forEach ((var , types ) -> {
4190
- types .stream ().filter (t -> t != null && t != UNKNOWN_PARAMETER_TYPE ) // GROOVY-6099, GROOVY-10294
4191
- .reduce (WideningCategories ::lowestUpperBound ).ifPresent (type -> {
4192
- assignments .put (var , type );
4193
- storeType (var , type );
4194
+ if (typeCheckingContext .ifElseForWhileAssignmentTracker != null ){ // GROOVY-11488
4195
+ typeCheckingContext .ifElseForWhileAssignmentTracker .forEach ((var , types ) -> {
4196
+ types .stream ().filter (t -> t != null && t != UNKNOWN_PARAMETER_TYPE ) // GROOVY-6099, GROOVY-10294
4197
+ .reduce (WideningCategories ::lowestUpperBound ).ifPresent (type -> {
4198
+ assignments .put (var , type );
4199
+ storeType (var , type );
4200
+ });
4194
4201
});
4195
- });
4202
+ }
4196
4203
typeCheckingContext .ifElseForWhileAssignmentTracker = oldTracker ;
4197
4204
// GROOVY-9786, GROOVY-11450: nested conditional assignments
4198
4205
if (oldTracker != null ) {
0 commit comments