Skip to content

Commit 82c229d

Browse files
committed
Fix #6033: don't throw exception in case of NoDenotation
NoDenotation may result from a normal capture conversion. Blindly throwing an error will cause unncessary compile crash.
1 parent 8ecc927 commit 82c229d

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,15 +2076,14 @@ object TypeComparer {
20762076
/** Show trace of comparison operations when performing `op` as result string */
20772077
def explaining[T](say: String => Unit)(op: Context => T)(implicit ctx: Context): T = {
20782078
val nestedCtx = ctx.fresh.setTypeComparerFn(new ExplainingTypeComparer(_))
2079-
val res = op(nestedCtx)
2080-
say(nestedCtx.typeComparer.lastTrace())
2079+
val res = try { op(nestedCtx) } finally { say(nestedCtx.typeComparer.lastTrace()) }
20812080
res
20822081
}
20832082

20842083
/** Like [[explaining]], but returns the trace instead */
20852084
def explained[T](op: Context => T)(implicit ctx: Context): String = {
20862085
var trace: String = null
2087-
explaining(trace = _)(op)
2086+
try { explaining(trace = _)(op) } catch { case ex: Throwable => ex.printStackTrace }
20882087
trace
20892088
}
20902089
}

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,11 +1924,21 @@ object Types {
19241924
param.derivedSingleDenotation(param, argInfo)
19251925
}
19261926
else {
1927-
if (!ctx.reporter.errorsReported)
1928-
throw new TypeError(
1929-
i"""bad parameter reference $this at ${ctx.phase}
1930-
|the parameter is ${param.showLocated} but the prefix $prefix
1931-
|does not define any corresponding arguments.""")
1927+
// Don't throw exception below, as capture conversion in
1928+
//
1929+
// Array[_] | Null <: Array[Int]
1930+
//
1931+
// will result in the following check:
1932+
//
1933+
// Int <: (Array[_] | Null) # T
1934+
//
1935+
// See tests/pos/i6033.scala
1936+
//
1937+
// if (!ctx.reporter.errorsReported)
1938+
// throw new TypeError(
1939+
// i"""bad parameter reference $this at ${ctx.phase}
1940+
// |the parameter is ${param.showLocated} but the prefix $prefix
1941+
// |does not define any corresponding arguments.""")
19321942
NoDenotation
19331943
}
19341944
}

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,8 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
405405

406406
/** Is `tp1` a subtype of `tp2`? */
407407
def isSubType(tp1: Type, tp2: Type): Boolean = {
408+
debug.println(TypeComparer.explained(implicit ctx => tp1 <:< tp2))
408409
val res = (tp1 != nullType || tp2 == nullType) && tp1 <:< tp2
409-
debug.println(s"${tp1} <:< ${tp2} = $res")
410410
res
411411
}
412412

tests/pos/i6033.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Test {
2+
def f(a: Array[_]|Null): Unit = a match {
3+
case x: Array[Int] =>
4+
}
5+
}

0 commit comments

Comments
 (0)