Skip to content

Commit efc48c3

Browse files
committed
Fix #6287: Reset opaque companions in ElimOpaque
1 parent 1c5b8a4 commit efc48c3

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

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

+16-10
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,21 @@ class ElimOpaque extends MiniPhase with DenotTransformer {
2828
// base types of opaque aliases change
2929
override def changesBaseTypes = true
3030

31-
def transform(ref: SingleDenotation)(implicit ctx: Context): SingleDenotation =
32-
if (ref.symbol.isOpaqueHelper)
33-
ref match {
34-
case sym: SymDenotation =>
35-
sym.copySymDenotation(
36-
info = TypeAlias(sym.opaqueAlias),
37-
initFlags = sym.flags &~ (Opaque | Deferred))
38-
case _ =>
39-
ref.derivedSingleDenotation(ref.symbol, TypeAlias(ref.info.extractOpaqueAlias))
31+
def transform(ref: SingleDenotation)(implicit ctx: Context): SingleDenotation = {
32+
val sym = ref.symbol
33+
ref match {
34+
case ref: SymDenotation if sym.isOpaqueHelper =>
35+
ref.copySymDenotation(
36+
info = TypeAlias(ref.opaqueAlias),
37+
initFlags = ref.flags &~ (Opaque | Deferred))
38+
case ref: SymDenotation if sym.isOpaqueCompanion =>
39+
val ref1 = ref.copySymDenotation(initFlags = ref.flags &~ Opaque)
40+
ref1.registeredCompanion = NoSymbol
41+
ref1
42+
case _ if sym.isOpaqueHelper =>
43+
ref.derivedSingleDenotation(sym, TypeAlias(ref.info.extractOpaqueAlias))
44+
case _ =>
45+
ref
4046
}
41-
else ref
47+
}
4248
}

tests/pos/i6287.scala

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
object O{
2+
def m() = {
3+
opaque type T = Int
4+
object T
5+
}
6+
}
7+
object A {
8+
{
9+
opaque type T = Int
10+
object T
11+
println
12+
}
13+
}

0 commit comments

Comments
 (0)