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