From 740ca026c1ef4862b98aa9e8397ded421a18e90b Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 22 Dec 2019 17:47:28 +0100 Subject: [PATCH] Fix #7822: Avoid crash in liftToThis --- compiler/src/dotty/tools/dotc/core/TypeComparer.scala | 2 +- tests/pos/i7822.scala | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i7822.scala diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index dc112a59403a..0ad1614dcbdf 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -1114,7 +1114,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w findEnclosingThis(tp.symbol.moduleClass, ctx.owner) case tp: TypeRef => val pre1 = liftToThis(tp.prefix) - if (pre1 ne tp.prefix) tp.withPrefix(pre1) else tp + if ((pre1 ne tp.prefix) && pre1.exists) tp.withPrefix(pre1) else tp case tp: ThisType if tp.cls.is(Package) => findEnclosingThis(tp.cls, ctx.owner) case tp: AppliedType => diff --git a/tests/pos/i7822.scala b/tests/pos/i7822.scala new file mode 100644 index 000000000000..f7349911fbe8 --- /dev/null +++ b/tests/pos/i7822.scala @@ -0,0 +1,5 @@ +class Code { + type Ctx +} +def foo(o0:Code,o1:Code) = new Code { type Ctx = o0.Ctx & o1.Ctx } +def foo0(o0:Code,o1:Code): Code { type Ctx = o0.Ctx & o1.Ctx } = foo(o0,o1)