Skip to content

Commit eadee84

Browse files
committed
Refactorings for clarity and to avoid unnecessary computation
1 parent 882b141 commit eadee84

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -860,17 +860,24 @@ class TreeUnpickler(reader: TastyReader,
860860
sym.info = TypeBounds.empty // needed to avoid cyclic references when unpickling rhs, see i3816.scala
861861
sym.setFlag(Provisional)
862862
val rhs = readTpt()(using localCtx)
863-
sym.info = new NoCompleter {
863+
864+
sym.info = new NoCompleter:
864865
override def completerTypeParams(sym: Symbol)(using Context) =
865866
rhs.tpe.typeParams
866-
}
867-
val tparamSyms = rhs match
868-
case LambdaTypeTree(tparams, body) => tparams.map(_.symbol.asType)
869-
case _ => Nil
870-
sym.info = sym.opaqueToBounds(
871-
checkNonCyclic(sym, rhs.tpe.toBounds, reportErrors = false),
872-
rhs, tparamSyms)
873-
if sym.isOpaqueAlias then sym.typeRef.recomputeDenot() // make sure we see the new bounds from now on
867+
868+
def opaqueToBounds(info: Type): Type =
869+
val tparamSyms = rhs match
870+
case LambdaTypeTree(tparams, body) => tparams.map(_.symbol.asType)
871+
case _ => Nil
872+
sym.opaqueToBounds(info, rhs, tparamSyms)
873+
874+
val info = checkNonCyclic(sym, rhs.tpe.toBounds, reportErrors = false)
875+
if sym.isOpaqueAlias then
876+
sym.info = opaqueToBounds(info)
877+
sym.typeRef.recomputeDenot() // make sure we see the new bounds from now on
878+
else
879+
sym.info = info
880+
874881
sym.resetFlag(Provisional)
875882
TypeDef(rhs)
876883
}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ class Namer { typer: Typer =>
425425
* is still missing its parents. Parents are set to Nil when completion starts and are
426426
* set to the actual parents later. If a superclass completes a subclass in one
427427
* of its parents, the parents of the superclass or some intervening class might
428-
* not yet be set. This situation can be detected by asking for the baseType of Any -
428+
* not yet be set. This situation can be detected by asking for the baseType of Any -
429429
* if that type does not exist, one of the base classes of this class misses its parents.
430430
* If this situation arises, the computation of the superclass might be imprecise.
431431
* For instance, in i12722.scala, the superclass of `IPersonalCoinOps` is computed
@@ -988,9 +988,12 @@ class Namer { typer: Typer =>
988988
val unsafeInfo = if (isDerived) rhsBodyType else abstracted(rhsBodyType)
989989

990990
def opaqueToBounds(info: Type): Type =
991-
if sym.isOpaqueAlias && info.typeParams.nonEmpty && info.hkResult.typeParams.nonEmpty then
992-
report.error(em"opaque type alias cannot have multiple type parameter lists", rhs.srcPos)
993-
sym.opaqueToBounds(info, rhs1, tparamSyms)
991+
if sym.isOpaqueAlias then
992+
if info.typeParams.nonEmpty && info.hkResult.typeParams.nonEmpty then
993+
report.error(em"opaque type alias cannot have multiple type parameter lists", rhs.srcPos)
994+
sym.opaqueToBounds(info, rhs1, tparamSyms)
995+
else
996+
info
994997

995998
if (isDerived) sym.info = unsafeInfo
996999
else {

0 commit comments

Comments
 (0)