From 0bdbb4e0f9fd2af8bf04ee478a528783df1abb94 Mon Sep 17 00:00:00 2001 From: Miles Sabin Date: Thu, 2 May 2019 17:15:32 +0100 Subject: [PATCH 1/4] Guard against NoSymbol in compareGADT Without the guard the test case crashes with an assert attempting get the owner of NoSymbol. --- compiler/src/dotty/tools/dotc/core/TypeComparer.scala | 2 +- tests/pos/dep-match.scala | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 tests/pos/dep-match.scala diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index dcf03d4f51c7..1caa7f49e4c7 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -678,7 +678,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] { narrowGADTBounds(tp1, tp2, approx, isUpper = true)) && GADTusage(tp1.symbol) } - isSubType(hi1, tp2, approx.addLow) || compareGADT + isSubType(hi1, tp2, approx.addLow) || ((tp1.symbol ne NoSymbol) && compareGADT) case _ => def isNullable(tp: Type): Boolean = tp.widenDealias match { case tp: TypeRef => tp.symbol.isNullableClass diff --git a/tests/pos/dep-match.scala b/tests/pos/dep-match.scala new file mode 100644 index 000000000000..60907a8f5207 --- /dev/null +++ b/tests/pos/dep-match.scala @@ -0,0 +1,9 @@ +object Test { + type Foo = Int { type U } + type Bar[T] = T match { + case Unit => Unit + } + inline def baz(foo: Foo): Unit = { + val v: Bar[foo.U] = ??? + } +} From aafd56ef527f10ac2bdc82b384224de305085add Mon Sep 17 00:00:00 2001 From: Miles Sabin Date: Fri, 3 May 2019 10:51:06 +0100 Subject: [PATCH 2/4] Move the NoSymbol check to gadtBounds --- compiler/src/dotty/tools/dotc/core/TypeComparer.scala | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index 1caa7f49e4c7..b7c2607bbc27 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -678,7 +678,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] { narrowGADTBounds(tp1, tp2, approx, isUpper = true)) && GADTusage(tp1.symbol) } - isSubType(hi1, tp2, approx.addLow) || ((tp1.symbol ne NoSymbol) && compareGADT) + isSubType(hi1, tp2, approx.addLow) || compareGADT case _ => def isNullable(tp: Type): Boolean = tp.widenDealias match { case tp: TypeRef => tp.symbol.isNullableClass @@ -2107,8 +2107,11 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) { } override def gadtBounds(sym: Symbol)(implicit ctx: Context): TypeBounds = { - footprint += sym.typeRef - super.gadtBounds(sym) + if (sym eq NoSymbol) null + else { + footprint += sym.typeRef + super.gadtBounds(sym) + } } override def gadtAddLowerBound(sym: Symbol, b: Type): Boolean = { From 83cfad9a605eb1299a292a48ccead2c9914f6aff Mon Sep 17 00:00:00 2001 From: Miles Sabin Date: Fri, 3 May 2019 10:55:05 +0100 Subject: [PATCH 3/4] Use sym.exists --- compiler/src/dotty/tools/dotc/core/TypeComparer.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index b7c2607bbc27..c7da31c654e0 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -2107,7 +2107,7 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) { } override def gadtBounds(sym: Symbol)(implicit ctx: Context): TypeBounds = { - if (sym eq NoSymbol) null + if (!sym.exists) null else { footprint += sym.typeRef super.gadtBounds(sym) From 0b57c1dfc1264ffe488dda0a5e44271ae0688012 Mon Sep 17 00:00:00 2001 From: Miles Sabin Date: Fri, 3 May 2019 18:12:32 +0100 Subject: [PATCH 4/4] Only conditionalise adding to footprint --- compiler/src/dotty/tools/dotc/core/TypeComparer.scala | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index c7da31c654e0..865f2ab7eeb2 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -2107,20 +2107,17 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) { } override def gadtBounds(sym: Symbol)(implicit ctx: Context): TypeBounds = { - if (!sym.exists) null - else { - footprint += sym.typeRef - super.gadtBounds(sym) - } + if (sym.exists) footprint += sym.typeRef + super.gadtBounds(sym) } override def gadtAddLowerBound(sym: Symbol, b: Type): Boolean = { - footprint += sym.typeRef + if (sym.exists) footprint += sym.typeRef super.gadtAddLowerBound(sym, b) } override def gadtAddUpperBound(sym: Symbol, b: Type): Boolean = { - footprint += sym.typeRef + if (sym.exists) footprint += sym.typeRef super.gadtAddUpperBound(sym, b) }