Skip to content

Commit cd57149

Browse files
committed
Fix crash due to var x:T = _
1 parent 3cf5dcb commit cd57149

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
@@ -299,10 +299,7 @@ class CompilationTests extends ParallelTesting {
299299
@Test def checkInitNeg: Unit = {
300300
implicit val testGroup: TestGroup = TestGroup("checkInit")
301301
val options = defaultOptions.and("-Ycheck-init", "-Xfatal-warnings")
302-
aggregateTests(
303-
compileFilesInDir("tests/init/neg/", options),
304-
compileFilesInDir("tests/init/crash", options),
305-
)
302+
compileFilesInDir("tests/init/neg/", options)
306303
}.checkExpectedErrors()
307304

308305
@Test def checkInitCrash: Unit = {

0 commit comments

Comments
 (0)