Skip to content

Commit af0336a

Browse files
committed
Extra condition to harden IDE
We observed a crash in ensureConforms when running the IDE because the expected type was not a value type.
1 parent 7820b5f commit af0336a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)