Skip to content

Commit b4ee67b

Browse files
committed
Fix crash due to var x:T = _
1 parent abc00fa commit b4ee67b

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

compiler/src/dotty/tools/dotc/transform/init/Summarization.scala

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ package init
44

55
import core._
66
import Contexts.Context
7-
import ast.tpd._
87
import Decorators._
8+
import StdNames._
99
import Symbols._
1010
import Constants.Constant
1111
import Types._
12+
13+
import ast.tpd._
1214
import config.Printers.init
1315
import reporting.trace
1416

@@ -26,6 +28,10 @@ object Summarization {
2628
def analyze(expr: Tree)(implicit env: Env): Summary =
2729
trace("summarizing " + expr.show, init, s => Summary.show(s.asInstanceOf[Summary])) {
2830
val summary: Summary = expr match {
31+
case Ident(nme.WILDCARD) =>
32+
// TODO: disallow `var x: T = _`
33+
Summary.empty
34+
2935
case Ident(name) =>
3036
assert(name.isTermName, "type trees should not reach here")
3137
analyze(expr.tpe, expr)
@@ -229,7 +235,10 @@ object Summarization {
229235
val thisRef = ThisRef(thisTp.classSymbol.asClass)(source)
230236
val pot = SuperRef(thisRef, superTp.classSymbol.asClass)(source)
231237
Summary.empty + pot
232-
}
238+
239+
case _ =>
240+
throw new Exception("unexpected type: " + tp.show)
241+
}
233242

234243
if (env.isAlwaysInitialized(tp)) (Potentials.empty, summary._2)
235244
else summary

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,7 @@ class CompilationTests extends ParallelTesting {
285285
@Test def checkInitNeg: Unit = {
286286
implicit val testGroup: TestGroup = TestGroup("checkInit")
287287
val options = defaultOptions.and("-Ycheck-init", "-Xfatal-warnings")
288-
aggregateTests(
289-
compileFilesInDir("tests/init/neg/", options),
290-
compileFilesInDir("tests/init/crash", options),
291-
)
288+
compileFilesInDir("tests/init/neg/", options)
292289
}.checkExpectedErrors()
293290

294291
@Test def checkInitCrash: Unit = {

0 commit comments

Comments
 (0)