diff options
author | odersky <odersky@gmail.com> | 2016-01-06 18:05:03 +0100 |
---|---|---|
committer | odersky <odersky@gmail.com> | 2016-01-06 18:05:03 +0100 |
commit | 66e73e022db9bc5309e2a22dbc4547e95e1c10cb (patch) | |
tree | d304dd261c7ab25a022ee0e4eb2d04d5e534c4f9 /src | |
parent | 705a95f31dd659a2bdd13379cd80ea3fed964ff0 (diff) | |
parent | f9abfd54c30dab551472841ddd74fb467e755766 (diff) | |
download | dotty-66e73e022db9bc5309e2a22dbc4547e95e1c10cb.tar.gz dotty-66e73e022db9bc5309e2a22dbc4547e95e1c10cb.tar.bz2 dotty-66e73e022db9bc5309e2a22dbc4547e95e1c10cb.zip |
Merge pull request #1004 from dotty-staging/linker/types
Subtle changes to TypeComarer needed for Linker.
Diffstat (limited to 'src')
-rw-r--r-- | src/dotty/tools/dotc/core/TypeComparer.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 9 | ||||
-rw-r--r-- | src/dotty/tools/dotc/transform/ResolveSuper.scala | 57 |
3 files changed, 38 insertions, 30 deletions
diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala index d5d811542..f468a573f 100644 --- a/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/src/dotty/tools/dotc/core/TypeComparer.scala @@ -212,7 +212,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) diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 1086fcdd6..45897dd64 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -1753,8 +1753,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) = @@ -1825,6 +1826,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) diff --git a/src/dotty/tools/dotc/transform/ResolveSuper.scala b/src/dotty/tools/dotc/transform/ResolveSuper.scala index 26128cf33..e718a7e60 100644 --- a/src/dotty/tools/dotc/transform/ResolveSuper.scala +++ b/src/dotty/tools/dotc/transform/ResolveSuper.scala @@ -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. @@ -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) @@ -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 + } +} |