diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 363a9e34230e..769defc3e42c 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -5802,7 +5802,7 @@ object Types { case Range(infoLo: TypeBounds, infoHi: TypeBounds) => assert(variance == 0) if (!infoLo.isTypeAlias && !infoHi.isTypeAlias) propagate(infoLo, infoHi) - else range(defn.NothingType, tp.parent) + else range(defn.NothingType, parent) case Range(infoLo, infoHi) => propagate(infoLo, infoHi) case _ => diff --git a/tests/pos/i14349.min.scala b/tests/pos/i14349.min.scala new file mode 100644 index 000000000000..8922d73056d6 --- /dev/null +++ b/tests/pos/i14349.min.scala @@ -0,0 +1,13 @@ +class Inv[M] + +class Module: + type X + type Y + type M = Module { + type X = Module.this.X + type Y = Module.this.Y + } + def expose = new Inv[M] + def test = this match { case m => m.expose } + // was: leak: `(m : Module)` in `m.expose: Inv[? <: Module { X = m.X }]` + def res: Inv[_ <: Module] = this match { case m => m.expose } diff --git a/tests/pos/i14349.scala b/tests/pos/i14349.scala new file mode 100644 index 000000000000..05e4e1e3603f --- /dev/null +++ b/tests/pos/i14349.scala @@ -0,0 +1,19 @@ +trait Module: + self => + type M <: Module { + type X = self.X + type Y = self.Y + } + type X + type Y + + def expose: Expose[X, Y, M] + +trait Expose[ + X0, + Y0, + M <: Module { type X = X0; type Y = Y0 } +] + +def test(ms: Seq[Option[Module]]): Seq[Expose[_, _, _]] = + ms.collect { case Some(module) => module.expose }