@@ -940,8 +940,9 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
940940 def caseRest (pat : Tree )(implicit ctx : Context ) = {
941941 val pat1 = indexPattern.transform(pat)
942942 val guard1 = typedExpr(tree.guard, defn.BooleanType )
943- val body1 = ensureNoLocalRefs(typedExpr(tree.body, pt), pt, ctx.scope.toList)
944- .ensureConforms(pt)(originalCtx) // insert a cast if body does not conform to expected type if we disregard gadt bounds
943+ var body1 = ensureNoLocalRefs(typedExpr(tree.body, pt), pt, ctx.scope.toList)
944+ if (pt.isValueType) // insert a cast if body does not conform to expected type if we disregard gadt bounds
945+ body1 = body1.ensureConforms(pt)(originalCtx)
945946 assignType(cpy.CaseDef (tree)(pat1, guard1, body1), body1)
946947 }
947948
@@ -1183,7 +1184,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
11831184 val pt1 = fullyDefinedType(pt, " pattern variable" , tree.pos)
11841185 val body1 = typed(tree.body, pt1)
11851186 body1 match {
1186- case UnApply (fn, Nil , arg :: Nil ) if fn.symbol.owner == defn.ClassTagClass && ! body1.tpe.isError =>
1187+ case UnApply (fn, Nil , arg :: Nil )
1188+ if fn.symbol.exists && fn.symbol.owner == defn.ClassTagClass && ! body1.tpe.isError =>
11871189 // A typed pattern `x @ (e: T)` with an implicit `ctag: ClassTag[T]`
11881190 // was rewritten to `x @ ctag(e)` by `tryWithClassTag`.
11891191 // Rewrite further to `ctag(x @ e)`
0 commit comments