Skip to content

Commit afb25a0

Browse files
committed
Strengthen the bounds of opaque helper types
... to make them aliases of the original opaque types.
1 parent 2707c7b commit afb25a0

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,13 @@ object SymDenotations {
10651065
def opaqueAlias(implicit ctx: Context): Type = {
10661066
if (isOpaqueHelper) {
10671067
owner.asClass.classInfo.selfType match {
1068-
case RefinedType(_, _, TypeAlias(rinfo)) => rinfo
1068+
case RefinedType(_, _, TypeBounds(lo, _)) =>
1069+
def extractAlias(tp: Type): Type = tp match {
1070+
case OrType(alias, _) => alias
1071+
case HKTypeLambda(tparams, tp) =>
1072+
HKTypeLambda(tparams.map(_.paramInfo), extractAlias(tp))
1073+
}
1074+
extractAlias(lo)
10691075
}
10701076
}
10711077
else NoType

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -582,11 +582,12 @@ trait Checking {
582582
if (!tp.isStable) ctx.error(ex"$tp is not stable", pos)
583583

584584
/** Check that all type members of `tp` have realizable bounds */
585-
def checkRealizableBounds(cls: Symbol, pos: Position)(implicit ctx: Context): Unit = {
586-
val rstatus = boundsRealizability(cls.thisType)
587-
if (rstatus ne Realizable)
588-
ctx.error(ex"$cls cannot be instantiated since it${rstatus.msg}", pos)
589-
}
585+
def checkRealizableBounds(cls: Symbol, pos: Position)(implicit ctx: Context): Unit =
586+
if (!cls.is(Module)) { // module's have system generated self types, which are assumed to be good
587+
val rstatus = boundsRealizability(cls.thisType)
588+
if (rstatus ne Realizable)
589+
ctx.error(ex"$cls cannot be instantiated since it${rstatus.msg}", pos)
590+
}
590591

591592
/** Check that `tp` is a class type.
592593
* Also, if `traitReq` is true, check that `tp` is a trait.

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,10 @@ class Namer { typer: Typer =>
947947
// companion object, since that's where the rhs was defined.
948948
val aliasCtx = ctx.outer.fresh.setOwner(symbolOfTree(td))
949949
val alias = typedAheadType(rhs)(aliasCtx).tpe
950-
RefinedType(mt, localName, TypeAlias(alias))
950+
val original = cls.companionOpaqueType.typeRef
951+
val cmp = ctx.typeComparer
952+
val bounds = TypeBounds(cmp.orType(alias, original), cmp.andType(alias, original))
953+
RefinedType(mt, localName, bounds)
951954
case _ :: stats1 =>
952955
refineOpaqueCompanionSelfType(mt, stats1)
953956
}

0 commit comments

Comments
 (0)