@@ -407,7 +407,7 @@ private[optimizer] abstract class OptimizerCore(
407
407
val newThenp = transform(thenp, isStat)
408
408
val newElsep = transform(elsep, isStat)
409
409
val refinedType =
410
- constrainedLub(newThenp.tpe, newElsep.tpe, tree.tpe)
410
+ constrainedLub(newThenp.tpe, newElsep.tpe, tree.tpe, isStat )
411
411
foldIf(newCond, newThenp, newElsep)(refinedType)
412
412
}
413
413
@@ -454,7 +454,7 @@ private[optimizer] abstract class OptimizerCore(
454
454
transform(handler, isStat)(handlerScope)
455
455
}
456
456
457
- val refinedType = constrainedLub(newBlock.tpe, newHandler.tpe, tree.tpe)
457
+ val refinedType = constrainedLub(newBlock.tpe, newHandler.tpe, tree.tpe, isStat )
458
458
TryCatch (newBlock, LocalIdent (newName)(errVar.pos), newOriginalName,
459
459
newHandler)(refinedType)
460
460
@@ -479,7 +479,7 @@ private[optimizer] abstract class OptimizerCore(
479
479
val newDefault = transform(default, isStat)
480
480
481
481
val refinedType = (newDefault.tpe :: newCases.map(_._2.tpe))
482
- .reduce(constrainedLub(_, _, tree.tpe))
482
+ .reduce(constrainedLub(_, _, tree.tpe, isStat ))
483
483
484
484
Match (newSelector, newCases, newDefault)(refinedType)
485
485
}
@@ -1190,7 +1190,7 @@ private[optimizer] abstract class OptimizerCore(
1190
1190
val newThenp = finishTransformExpr(tthenpNoLocalDef)
1191
1191
val newElsep = finishTransformExpr(telsepNoLocalDef)
1192
1192
val refinedType =
1193
- constrainedLub(newThenp.tpe, newElsep.tpe, tree.tpe)
1193
+ constrainedLub(newThenp.tpe, newElsep.tpe, tree.tpe, isStat = false )
1194
1194
cont(foldIf(newCond, newThenp, newElsep)(
1195
1195
refinedType).toPreTransform)
1196
1196
}
@@ -1200,7 +1200,7 @@ private[optimizer] abstract class OptimizerCore(
1200
1200
val newThenp = transformExpr(thenp)
1201
1201
val newElsep = transformExpr(elsep)
1202
1202
val refinedType =
1203
- constrainedLub(newThenp.tpe, newElsep.tpe, tree.tpe)
1203
+ constrainedLub(newThenp.tpe, newElsep.tpe, tree.tpe, isStat = false )
1204
1204
cont(foldIf(newCond, newThenp, newElsep)(
1205
1205
refinedType).toPreTransform)
1206
1206
}
@@ -5161,7 +5161,7 @@ private[optimizer] abstract class OptimizerCore(
5161
5161
5162
5162
def doMakeTree (newBody : Tree , returnedTypes : List [Type ]): Tree = {
5163
5163
val refinedType =
5164
- returnedTypes.reduce(constrainedLub(_, _, resultType))
5164
+ returnedTypes.reduce(constrainedLub(_, _, resultType, isStat ))
5165
5165
val returnCount = returnedTypes.size - 1
5166
5166
5167
5167
tryOptimizePatternMatch(oldLabelName, newLabel, refinedType,
@@ -5538,23 +5538,26 @@ private[optimizer] abstract class OptimizerCore(
5538
5538
/** Finds a type as precise as possible which is a supertype of lhs and rhs
5539
5539
* but still a subtype of upperBound.
5540
5540
* Requires that lhs and rhs be subtypes of upperBound, obviously.
5541
+ *
5542
+ * The RefinedType version does not have an `isStat` flag, since RefinedTypes
5543
+ * only exist in a PreTransform context, which is always an expression context.
5541
5544
*/
5542
5545
private def constrainedLub (lhs : RefinedType , rhs : RefinedType ,
5543
5546
upperBound : Type ): RefinedType = {
5544
- if (upperBound == VoidType ) RefinedType (upperBound )
5547
+ if (upperBound == VoidType ) RefinedType (VoidType )
5545
5548
else if (lhs == rhs) lhs
5546
5549
else if (lhs.isNothingType) rhs
5547
5550
else if (rhs.isNothingType) lhs
5548
- else RefinedType (constrainedLub(lhs.base, rhs.base, upperBound))
5551
+ else RefinedType (constrainedLub(lhs.base, rhs.base, upperBound, isStat = false ))
5549
5552
}
5550
5553
5551
5554
/** Finds a type as precise as possible which is a supertype of lhs and rhs
5552
5555
* but still a subtype of upperBound.
5553
5556
* Requires that lhs and rhs be subtypes of upperBound, obviously.
5554
5557
*/
5555
- private def constrainedLub (lhs : Type , rhs : Type , upperBound : Type ): Type = {
5558
+ private def constrainedLub (lhs : Type , rhs : Type , upperBound : Type , isStat : Boolean ): Type = {
5556
5559
// TODO Improve this
5557
- if (upperBound == VoidType ) upperBound
5560
+ if (isStat || upperBound == VoidType ) VoidType
5558
5561
else if (lhs == rhs) lhs
5559
5562
else if (lhs == NothingType ) rhs
5560
5563
else if (rhs == NothingType ) lhs
0 commit comments