@@ -308,12 +308,12 @@ object PatternMatcher {
308
308
if (scrutinee.info.isNotNull || nonNull(scrutinee)) unappPlan
309
309
else TestPlan (NonNullTest , scrutinee, tree.pos, unappPlan, onFailure)
310
310
case Bind (name, body) =>
311
- val body1 = patternPlan(scrutinee, body, onSuccess, onFailure)
312
- if (name == nme.WILDCARD ) body1
311
+ if (name == nme.WILDCARD ) patternPlan(scrutinee, body, onSuccess, onFailure)
313
312
else {
313
+ // The type of `name` may refer to val in `body`, therefore should come after `body`
314
314
val bound = tree.symbol.asTerm
315
315
initializer(bound) = ref(scrutinee)
316
- LetPlan (bound, body1 )
316
+ patternPlan(scrutinee, body, LetPlan (bound, onSuccess), onFailure )
317
317
}
318
318
case Alternative (alts) =>
319
319
labelAbstract(onSuccess) { ons =>
@@ -839,7 +839,12 @@ object PatternMatcher {
839
839
else
840
840
If (emitCondition(plan).withPos(plan.pos), emit(plan.onSuccess), emit(plan.onFailure))
841
841
case LetPlan (sym, body) =>
842
- seq(ValDef (sym, initializer(sym).ensureConforms(sym.info)) :: Nil , emit(body))
842
+ sym.info match {
843
+ case tmref : TermRef if tmref.isStable => // check #1463, no type cast needed
844
+ seq(ValDef (sym, ref(tmref)) :: Nil , emit(body))
845
+ case _ =>
846
+ seq(ValDef (sym, initializer(sym).ensureConforms(sym.info)) :: Nil , emit(body))
847
+ }
843
848
case LabelledPlan (label, body, params) =>
844
849
label.info = MethodType .fromSymbols(params, resultType)
845
850
val labelDef = DefDef (label, Nil , params :: Nil , resultType, emit(labelled(label)))
0 commit comments