Skip to content

Commit b3f2aee

Browse files
authored
Merge pull request #8751 from dotty-staging/fix-#8750
Fix #8750: Strip opaque refinements when checking self type
2 parents 06a118e + f3f537b commit b3f2aee

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,16 @@ object Checking {
175175
if (cls.isOneOf(AbstractOrTrait))
176176
ctx.error(CantInstantiateAbstractClassOrTrait(cls, isTrait = cls.is(Trait)), posd.sourcePos)
177177
if (!cls.is(Module)) {
178+
def (tp: Type).stripOpaques: Type = tp match
179+
case RefinedType(parent, name, _) if cls.info.decl(name).symbol.isOpaqueAlias =>
180+
parent.stripOpaques
181+
case _ =>
182+
tp
178183
// Create a synthetic singleton type instance, and check whether
179184
// it conforms to the self type of the class as seen from that instance.
180185
val stp = SkolemType(tp)
181-
val selfType = cls.asClass.givenSelfType.asSeenFrom(stp, cls)
186+
val selfType =
187+
cls.asClass.givenSelfType.stripOpaques.asSeenFrom(stp, cls)
182188
if (selfType.exists && !(stp <:< selfType))
183189
ctx.error(DoesNotConformToSelfTypeCantBeInstantiated(tp, selfType), posd.sourcePos)
184190
}

tests/pos/i8750.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Abc:
2+
opaque type Log = Double
3+
4+
val v : Abc = new Abc

0 commit comments

Comments
 (0)