From ba75f190de5bf3e55b52803e8fd83e2538933153 Mon Sep 17 00:00:00 2001 From: Kacper Korban Date: Sun, 4 Sep 2022 15:26:22 +0200 Subject: [PATCH] Avoid adding NoSymbol to gadt constraints in TypeOps.instantiateToSubType fixes lampepfl#15964 --- compiler/src/dotty/tools/dotc/core/TypeOps.scala | 2 +- tests/pos/i15964.scala | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i15964.scala diff --git a/compiler/src/dotty/tools/dotc/core/TypeOps.scala b/compiler/src/dotty/tools/dotc/core/TypeOps.scala index c087aac83cb8..b975c153212a 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala @@ -852,7 +852,7 @@ object TypeOps: val getAbstractSymbols = new TypeAccumulator[List[Symbol]]: def apply(xs: List[Symbol], tp: Type) = tp.dealias match - case tp: TypeRef if !tp.symbol.isClass => foldOver(tp.symbol :: xs, tp) + case tp: TypeRef if tp.symbol.exists && !tp.symbol.isClass => foldOver(tp.symbol :: xs, tp) case tp => foldOver(xs, tp) val syms2 = getAbstractSymbols(Nil, tp2).reverse if syms2.nonEmpty then ctx.gadt.addToConstraint(syms2) diff --git a/tests/pos/i15964.scala b/tests/pos/i15964.scala new file mode 100644 index 000000000000..5713f19e4419 --- /dev/null +++ b/tests/pos/i15964.scala @@ -0,0 +1,16 @@ +// scalac: -Werror +sealed trait T +class C extends T + +class AClass +type AType = AClass { + type TypeMember <: T +} + +def list2Product( + atype: AType, + opt: atype.TypeMember +): Unit = + opt match { + case _: C => () + }