Skip to content

Commit e317084

Browse files
committed
Handle opaque types in computeAsSeenFrom
1 parent 5381a3d commit e317084

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,12 +1114,28 @@ object Denotations {
11141114
type AsSeenFromResult = SingleDenotation
11151115
protected def computeAsSeenFrom(pre: Type)(implicit ctx: Context): SingleDenotation = {
11161116
val symbol = this.symbol
1117-
val owner = this match {
1118-
case thisd: SymDenotation => thisd.owner
1119-
case _ => if (symbol.exists) symbol.owner else NoSymbol
1117+
def derived = {
1118+
val owner = this match {
1119+
case thisd: SymDenotation => thisd.owner
1120+
case _ => if (symbol.exists) symbol.owner else NoSymbol
1121+
}
1122+
if (!owner.membersNeedAsSeenFrom(pre) || symbol.is(NonMember)) this
1123+
else derivedSingleDenotation(symbol, symbol.info.asSeenFrom(pre, owner))
1124+
}
1125+
pre match {
1126+
case pre: ThisType if symbol.isOpaqueAlias && pre.cls == symbol.owner =>
1127+
symbol.normalizeOpaque()
1128+
def findRefined(tp: Type, name: Name): SingleDenotation = tp match {
1129+
case RefinedType(parent, rname, rinfo) =>
1130+
if (rname == name) derivedSingleDenotation(symbol, rinfo)
1131+
else findRefined(parent, name)
1132+
case _ =>
1133+
derived
1134+
}
1135+
findRefined(pre.underlying, symbol.name)
1136+
case _ =>
1137+
derived
11201138
}
1121-
if (!owner.membersNeedAsSeenFrom(pre) || symbol.is(NonMember)) this
1122-
else derivedSingleDenotation(symbol, symbol.info.asSeenFrom(pre, owner))
11231139
}
11241140

11251141
/** Does this denotation have all the `required` flags but none of the `excluded` flags?

tests/pos/export-opaque.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
object A {
2+
3+
object opaques {
4+
opaque type FlagSet = Long
5+
def FlagSet(bits: Long): FlagSet = bits
6+
}
7+
//type FlagSet = opaques.FlagSet
8+
//def FlagSet(bits: Long): FlagSet = opaques.FlagSet(bits)
9+
export opaques.FlagSet
10+
11+
}

tests/pos/implicit-scope.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ object A {
22

33
object opaques {
44
opaque type FlagSet = Long
5-
def FlagSet(bits: Long): FlagSet = bits.asInstanceOf // !!!
5+
def FlagSet(bits: Long): FlagSet = bits
66
def toBits(fs: FlagSet): Long = fs
77
}
88
val someFlag = FlagSet(1)

0 commit comments

Comments
 (0)