Skip to content

Subtle changes to TypeComarer needed for Linker. #1004

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 4 commits into from
Jan 6, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
val cls1 = tp1.cls
cls1.classInfo.selfType.derivesFrom(cls2) &&
cls2.classInfo.selfType.derivesFrom(cls1)
case tp1: TermRef if cls2.is(Module) && cls2.eq(tp1.widen.typeSymbol) =>
case tp1: NamedType if cls2.is(Module) && cls2.eq(tp1.widen.typeSymbol) =>
cls2.isStaticOwner ||
isSubType(tp1.prefix, cls2.owner.thisType) ||
secondTry(tp1, tp2)
Expand Down
9 changes: 7 additions & 2 deletions src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1695,8 +1695,9 @@ object Types {
override def computeHash = unsupported("computeHash")
}

final class TermRefWithFixedSym(prefix: Type, name: TermName, val fixedSym: TermSymbol) extends TermRef(prefix, name) with WithFixedSym
final class TypeRefWithFixedSym(prefix: Type, name: TypeName, val fixedSym: TypeSymbol) extends TypeRef(prefix, name) with WithFixedSym
// Those classes are non final as Linker extends them.
class TermRefWithFixedSym(prefix: Type, name: TermName, val fixedSym: TermSymbol) extends TermRef(prefix, name) with WithFixedSym
class TypeRefWithFixedSym(prefix: Type, name: TypeName, val fixedSym: TypeSymbol) extends TypeRef(prefix, name) with WithFixedSym

/** Assert current phase does not have erasure semantics */
private def assertUnerased()(implicit ctx: Context) =
Expand Down Expand Up @@ -1767,6 +1768,10 @@ object Types {
withFixedSym(prefix, name, sym)
else if (sym.defRunId != NoRunId && sym.isCompleted)
withSig(prefix, name, sym.signature) withSym (sym, sym.signature)
// Linker note:
// this is problematic, as withSig method could return a hash-consed refference
// that could have symbol already set making withSym trigger a double-binding error
// ./tests/run/absoverride.scala demonstates this
else
all(prefix, name) withSym (sym, Signature.NotAMethod)

Expand Down
57 changes: 30 additions & 27 deletions src/dotty/tools/dotc/transform/ResolveSuper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import ast.Trees._
import util.Positions._
import Names._
import collection.mutable
import ResolveSuper._

/** This phase adds super accessors and method overrides where
* linearization differs from Java's rule for default methods in interfaces.
Expand Down Expand Up @@ -51,33 +52,6 @@ class ResolveSuper extends MiniPhaseTransform with IdentityDenotTransformer { th
override def runsAfter = Set(classOf[ElimByName], // verified empirically, need to figure out what the reason is.
classOf[AugmentScala2Traits])

/** Returns the symbol that is accessed by a super-accessor in a mixin composition.
*
* @param base The class in which everything is mixed together
* @param member The symbol statically referred to by the superaccessor in the trait
*/
private def rebindSuper(base: Symbol, acc: Symbol)(implicit ctx: Context): Symbol = {
var bcs = base.info.baseClasses.dropWhile(acc.owner != _).tail
var sym: Symbol = NoSymbol
val unexpandedAccName =
if (acc.is(ExpandedName)) // Cannot use unexpandedName because of #765. t2183.scala would fail if we did.
acc.name
.drop(acc.name.indexOfSlice(nme.EXPAND_SEPARATOR ++ nme.SUPER_PREFIX))
.drop(nme.EXPAND_SEPARATOR.length)
else acc.name
val SuperAccessorName(memberName) = unexpandedAccName: Name // dotty deviation: ": Name" needed otherwise pattern type is neither a subtype nor a supertype of selector type
ctx.debuglog(i"starting rebindsuper from $base of ${acc.showLocated}: ${acc.info} in $bcs, name = $memberName")
while (bcs.nonEmpty && sym == NoSymbol) {
val other = bcs.head.info.nonPrivateDecl(memberName)
if (ctx.settings.debug.value)
ctx.log(i"rebindsuper ${bcs.head} $other deferred = ${other.symbol.is(Deferred)}")
sym = other.matchingDenotation(base.thisType, base.thisType.memberInfo(acc)).symbol
bcs = bcs.tail
}
assert(sym.exists)
sym
}

override def transformTemplate(impl: Template)(implicit ctx: Context, info: TransformerInfo) = {
val cls = impl.symbol.owner.asClass
val ops = new MixinOps(cls, thisTransform)
Expand Down Expand Up @@ -110,3 +84,32 @@ class ResolveSuper extends MiniPhaseTransform with IdentityDenotTransformer { th

private val PrivateOrAccessorOrDeferred = Private | Accessor | Deferred
}

object ResolveSuper{
/** Returns the symbol that is accessed by a super-accessor in a mixin composition.
*
* @param base The class in which everything is mixed together
* @param acc The symbol statically referred to by the superaccessor in the trait
*/
def rebindSuper(base: Symbol, acc: Symbol)(implicit ctx: Context): Symbol = {
var bcs = base.info.baseClasses.dropWhile(acc.owner != _).tail
var sym: Symbol = NoSymbol
val unexpandedAccName =
if (acc.is(ExpandedName)) // Cannot use unexpandedName because of #765. t2183.scala would fail if we did.
acc.name
.drop(acc.name.indexOfSlice(nme.EXPAND_SEPARATOR ++ nme.SUPER_PREFIX))
.drop(nme.EXPAND_SEPARATOR.length)
else acc.name
val SuperAccessorName(memberName) = unexpandedAccName: Name // dotty deviation: ": Name" needed otherwise pattern type is neither a subtype nor a supertype of selector type
ctx.debuglog(i"starting rebindsuper from $base of ${acc.showLocated}: ${acc.info} in $bcs, name = $memberName")
while (bcs.nonEmpty && sym == NoSymbol) {
val other = bcs.head.info.nonPrivateDecl(memberName)
if (ctx.settings.debug.value)
ctx.log(i"rebindsuper ${bcs.head} $other deferred = ${other.symbol.is(Deferred)}")
sym = other.matchingDenotation(base.thisType, base.thisType.memberInfo(acc)).symbol
bcs = bcs.tail
}
assert(sym.exists)
sym
}
}