Skip to content

Commit c22a180

Browse files
committed
Cleanups
1 parent 71f8413 commit c22a180

File tree

6 files changed

+53
-10
lines changed

6 files changed

+53
-10
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ class TreeUnpickler(reader: TastyReader,
817817
if (companion.exists && isCodefined) sym.registerCompanion(companion)
818818
TypeDef(readTemplate(localCtx))
819819
} else {
820-
sym.info = TypeBounds.empty // needed to avoid cyclic references when unpicklin rhs, see i3816.scala
820+
sym.info = TypeBounds.empty // needed to avoid cyclic references when unpickling rhs, see i3816.scala
821821
sym.setFlag(Provisional)
822822
val rhs = readTpt()(localCtx)
823823
sym.info = new NoCompleter {
@@ -828,8 +828,8 @@ class TreeUnpickler(reader: TastyReader,
828828
case _: TypeBounds | _: ClassInfo => checkNonCyclic(sym, rhs.tpe, reportErrors = false)
829829
case _ => rhs.tpe.toBounds
830830
}
831-
sym.resetFlag(Provisional)
832831
sym.normalizeOpaque()
832+
sym.resetFlag(Provisional)
833833
TypeDef(rhs)
834834
}
835835
case PARAM =>

compiler/src/dotty/tools/dotc/transform/ElimOpaque.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ class ElimOpaque extends MiniPhase with DenotTransformer {
4747
info = cinfo.derivedClassInfo(selfInfo = strippedSelfType),
4848
initFlags = ref.flags &~ Opaque)
4949
case _ =>
50+
// This is dubbious as it means that we do not see the alias from an external reference
51+
// which has tupe UniqueRefDenotion instead of SymDenotation. But to correctly recompote
52+
// the alias we'd need a prefix, which we do not have here. To fix this, we'd have to
53+
// maintain a prefix in UniqueRefDenotations and JointRefDenotations.
5054
ref
5155
}
5256
}

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,21 +1467,18 @@ class Namer { typer: Typer =>
14671467
sym.info = NoCompleter
14681468
sym.info = checkNonCyclic(sym, unsafeInfo, reportErrors = true)
14691469
}
1470+
sym.normalizeOpaque()
14701471
sym.resetFlag(Provisional)
14711472

14721473
// Here we pay the price for the cavalier setting info to TypeBounds.empty above.
14731474
// We need to compensate by reloading the denotation of references that might
14741475
// still contain the TypeBounds.empty. If we do not do this, stdlib factories
14751476
// fail with a bounds error in PostTyper.
1476-
def ensureUpToDate(tp: Type, outdated: Type) = tp match {
1477-
case tref: TypeRef if tref.info == outdated && sym.info != outdated =>
1478-
tref.recomputeDenot()
1479-
case _ =>
1480-
}
1481-
sym.normalizeOpaque()
1477+
def ensureUpToDate(tref: TypeRef, outdated: Type) =
1478+
if (tref.info == outdated && sym.info != outdated) tref.recomputeDenot()
14821479
ensureUpToDate(sym.typeRef, dummyInfo1)
14831480
if (dummyInfo2 `ne` dummyInfo1) ensureUpToDate(sym.typeRef, dummyInfo2)
1484-
ensureUpToDate(sym.typeRef.appliedTo(tparamSyms.map(_.typeRef)), TypeBounds.empty)
1481+
14851482
sym.info
14861483
}
14871484
}

tests/neg/no-self-leaks.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
trait C { this: { type T = Int } =>
2+
3+
type T
4+
val x: T
5+
}
6+
7+
class D extends C {
8+
type T = Int
9+
val x = 10
10+
}
11+
12+
object Test {
13+
14+
val c: C = new D
15+
val y: c.T = c.x
16+
val x: Int = c.x // error
17+
val z: Int = y // error
18+
}

tests/neg/simple-opaque.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
object o {
2+
3+
opaque type T = Int
4+
val x: T = 322
5+
6+
def toT(x: Int): T = x
7+
8+
object oo {
9+
def apply222(x: Int): T = x
10+
}
11+
}
12+
13+
object Test {
14+
15+
val y: o.T = o.x
16+
val x: Int = o.x // error
17+
val z: Int = y // error
18+
19+
val t = o.toT(11)
20+
val i: Int = t // error
21+
22+
val t2: o.T = o.oo.apply222(22)
23+
val i2: Int = t2 // error
24+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
type A = B // error: recursion limit exceeded
1+
type A = B // error: recursion limit exceeded // error: recursion limit exceeded
22

0 commit comments

Comments
 (0)