Skip to content

Commit f6aa8f8

Browse files
authored
Merge pull request #10785 from dotty-staging/fix-10769
Fix #10769: change synthesized type in def ordinal
2 parents 5672999 + f810049 commit f6aa8f8

File tree

5 files changed

+73
-5
lines changed

5 files changed

+73
-5
lines changed

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,6 +1408,37 @@ object SymDenotations {
14081408
def namedType(using Context): NamedType =
14091409
if (isType) typeRef else termRef
14101410

1411+
/** Like typeRef, but objects in the prefix are represented by their singleton type,
1412+
* this means we output `pre.O.member` rather than `pre.O$.this.member`.
1413+
*
1414+
* This is required to avoid owner crash in ExplicitOuter.
1415+
* See tests/pos/i10769.scala
1416+
*/
1417+
def reachableTypeRef(using Context) =
1418+
TypeRef(owner.reachableThisType, symbol)
1419+
1420+
/** Like termRef, but objects in the prefix are represented by their singleton type,
1421+
* this means we output `pre.O.member` rather than `pre.O$.this.member`.
1422+
*
1423+
* This is required to avoid owner crash in ExplicitOuter.
1424+
* See tests/pos/i10769.scala
1425+
*/
1426+
def reachableTermRef(using Context) =
1427+
TermRef(owner.reachableThisType, symbol)
1428+
1429+
/** Like thisType, but objects in the type are represented by their singleton type,
1430+
* this means we output `pre.O.member` rather than `pre.O$.this.member`.
1431+
*/
1432+
def reachableThisType(using Context): Type =
1433+
if this.is(Package) then
1434+
symbol.thisType
1435+
else if this.isTerm then
1436+
NoPrefix
1437+
else if this.is(Module) then
1438+
TermRef(owner.reachableThisType, this.sourceModule)
1439+
else
1440+
ThisType.raw(TypeRef(owner.reachableThisType, symbol.asType))
1441+
14111442
/** The variance of this type parameter or type member as a subset of
14121443
* {Covariant, Contravariant}
14131444
*/

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,9 @@ object SymUtils:
223223
else owner.isLocal
224224
}
225225

226-
/** The typeRef with wildcard arguments for each type parameter */
227-
def rawTypeRef(using Context) =
228-
self.typeRef.appliedTo(self.typeParams.map(_ => TypeBounds.emptyPolyKind))
226+
/** The reachable typeRef with wildcard arguments for each type parameter */
227+
def reachableRawTypeRef(using Context) =
228+
self.reachableTypeRef.appliedTo(self.typeParams.map(_ => TypeBounds.emptyPolyKind))
229229

230230
/** Is symbol a quote operation? */
231231
def isQuote(using Context): Boolean =

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ class SyntheticMembers(thisPhase: DenotTransformer) {
521521
else {
522522
val cases =
523523
for ((child, idx) <- cls.children.zipWithIndex) yield {
524-
val patType = if (child.isTerm) child.termRef else child.rawTypeRef
524+
val patType = if (child.isTerm) child.reachableTermRef else child.reachableRawTypeRef
525525
val pat = Typed(untpd.Ident(nme.WILDCARD).withType(patType), TypeTree(patType))
526526
CaseDef(pat, EmptyTree, Literal(Constant(idx)))
527527
}
@@ -563,7 +563,7 @@ class SyntheticMembers(thisPhase: DenotTransformer) {
563563
if (existing.exists && !existing.is(Deferred)) existing
564564
else {
565565
val monoType =
566-
newSymbol(clazz, tpnme.MirroredMonoType, Synthetic, TypeAlias(linked.rawTypeRef), coord = clazz.coord)
566+
newSymbol(clazz, tpnme.MirroredMonoType, Synthetic, TypeAlias(linked.reachableRawTypeRef), coord = clazz.coord)
567567
newBody = newBody :+ TypeDef(monoType).withSpan(ctx.owner.span.focus)
568568
monoType.entered
569569
}

tests/pos/i10769.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package stm
2+
3+
trait STMLike[F[_]] {
4+
import Internals._
5+
6+
sealed abstract class Txn[+A] {}
7+
8+
object Txn {
9+
def abort[A](e: Throwable): Txn[A] = Abort(e)
10+
}
11+
12+
object Internals {
13+
case class Abort(error: Throwable) extends Txn[Nothing]
14+
case object Noop extends Txn[Nothing]
15+
}
16+
}

tests/pos/i10769b.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package stm
2+
3+
trait STMLike[F[_]] {
4+
import Internals._
5+
6+
sealed abstract class Txn[+A] {}
7+
8+
object Txn {
9+
def abort[A](e: Throwable): Txn[A] = Abort(e)
10+
}
11+
12+
object Internals {
13+
case class Abort(error: Throwable) extends Txn[Nothing]
14+
case object Noop extends Txn[Nothing]
15+
}
16+
17+
class Foo {
18+
case class Abort(error: Throwable) extends Txn[Nothing]
19+
case object Noop extends Txn[Nothing]
20+
}
21+
}

0 commit comments

Comments
 (0)