From f3f537b480626b76ffc29f5976c9da8ed9f84912 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 20 Apr 2020 10:24:17 +0200 Subject: [PATCH] Fix #8750: Strip opaque refinements when checking self type Strip opaque refinements when checking that a class is instantiatable --- compiler/src/dotty/tools/dotc/typer/Checking.scala | 8 +++++++- tests/pos/i8750.scala | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i8750.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 89e4d6354713..77ab4829baa4 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -175,10 +175,16 @@ object Checking { if (cls.isOneOf(AbstractOrTrait)) ctx.error(CantInstantiateAbstractClassOrTrait(cls, isTrait = cls.is(Trait)), posd.sourcePos) if (!cls.is(Module)) { + def (tp: Type).stripOpaques: Type = tp match + case RefinedType(parent, name, _) if cls.info.decl(name).symbol.isOpaqueAlias => + parent.stripOpaques + case _ => + tp // Create a synthetic singleton type instance, and check whether // it conforms to the self type of the class as seen from that instance. val stp = SkolemType(tp) - val selfType = cls.asClass.givenSelfType.asSeenFrom(stp, cls) + val selfType = + cls.asClass.givenSelfType.stripOpaques.asSeenFrom(stp, cls) if (selfType.exists && !(stp <:< selfType)) ctx.error(DoesNotConformToSelfTypeCantBeInstantiated(tp, selfType), posd.sourcePos) } diff --git a/tests/pos/i8750.scala b/tests/pos/i8750.scala new file mode 100644 index 000000000000..a88cfb51acd2 --- /dev/null +++ b/tests/pos/i8750.scala @@ -0,0 +1,4 @@ +class Abc: + opaque type Log = Double + +val v : Abc = new Abc \ No newline at end of file