Skip to content

Fix #10769: change synthesized type in def ordinal #10785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1410,6 +1410,33 @@ object SymDenotations {
def namedType(using Context): NamedType =
if (isType) typeRef else termRef

/** The typeRef where `pre.O$.this` is changed to `pre.O.type` if `O` is a non-static object
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These documentation comments need to be updated since we also do this for static objects now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

*
* This is required to avoid owner crash in ExplicitOuter.
* See tests/pos/i10769.scala
*/
def reachableTypeRef(using Context) =
TypeRef(owner.reachableThisType, symbol)

/** The termRef where `pre.O$.this` is changed to `pre.O.type` if `O` is a non-static object
*
* This is required to avoid owner crash in ExplicitOuter.
* See tests/pos/i10769.scala
*/
def reachableTermRef(using Context) =
TermRef(owner.reachableThisType, symbol)

/** The thisType where `pre.O$.this` is changed to `pre.O.type` if `O` is a non-static object */
def reachableThisType(using Context): Type =
if this.is(Package) then
symbol.thisType
else if this.isTerm then
NoPrefix
else if this.is(Module) then
TermRef(owner.reachableThisType, this.sourceModule)
else
ThisType.raw(TypeRef(owner.reachableThisType, symbol.asType))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What abotu the ThisType.raw here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is different, as we need to call owner. reachableThisType.


/** The variance of this type parameter or type member as a subset of
* {Covariant, Contravariant}
*/
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/SymUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ object SymUtils:
else owner.isLocal
}

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

/** Is symbol a quote operation? */
def isQuote(using Context): Boolean =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ class SyntheticMembers(thisPhase: DenotTransformer) {
else {
val cases =
for ((child, idx) <- cls.children.zipWithIndex) yield {
val patType = if (child.isTerm) child.termRef else child.rawTypeRef
val patType = if (child.isTerm) child.reachableTermRef else child.reachableRawTypeRef
val pat = Typed(untpd.Ident(nme.WILDCARD).withType(patType), TypeTree(patType))
CaseDef(pat, EmptyTree, Literal(Constant(idx)))
}
Expand Down Expand Up @@ -563,7 +563,7 @@ class SyntheticMembers(thisPhase: DenotTransformer) {
if (existing.exists && !existing.is(Deferred)) existing
else {
val monoType =
newSymbol(clazz, tpnme.MirroredMonoType, Synthetic, TypeAlias(linked.rawTypeRef), coord = clazz.coord)
newSymbol(clazz, tpnme.MirroredMonoType, Synthetic, TypeAlias(linked.reachableRawTypeRef), coord = clazz.coord)
newBody = newBody :+ TypeDef(monoType).withSpan(ctx.owner.span.focus)
monoType.entered
}
Expand Down
16 changes: 16 additions & 0 deletions tests/pos/i10769.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package stm

trait STMLike[F[_]] {
import Internals._

sealed abstract class Txn[+A] {}

object Txn {
def abort[A](e: Throwable): Txn[A] = Abort(e)
}

object Internals {
case class Abort(error: Throwable) extends Txn[Nothing]
case object Noop extends Txn[Nothing]
}
}
21 changes: 21 additions & 0 deletions tests/pos/i10769b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package stm

trait STMLike[F[_]] {
import Internals._

sealed abstract class Txn[+A] {}

object Txn {
def abort[A](e: Throwable): Txn[A] = Abort(e)
}

object Internals {
case class Abort(error: Throwable) extends Txn[Nothing]
case object Noop extends Txn[Nothing]
}

class Foo {
case class Abort(error: Throwable) extends Txn[Nothing]
case object Noop extends Txn[Nothing]
}
}