aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-08-21 15:08:47 +0200
committerMartin Odersky <odersky@gmail.com>2015-08-21 15:08:47 +0200
commitaaae0df80376668d1c502857695b43d42083c888 (patch)
tree83aba7b1a390563c26b79a7f5cbfdc4b47a8a66b
parentcc5dce545e1150021bcd3d312574bdf3b657512c (diff)
downloaddotty-aaae0df80376668d1c502857695b43d42083c888.tar.gz
dotty-aaae0df80376668d1c502857695b43d42083c888.tar.bz2
dotty-aaae0df80376668d1c502857695b43d42083c888.zip
Workaround for #765
Avoid using unexpanded name because it can give wrong results for super accessors of symbolic names. See #765. Without this commit t2183.scala crashes the compiler.
-rw-r--r--src/dotty/tools/dotc/core/NameOps.scala5
-rw-r--r--src/dotty/tools/dotc/transform/ResolveSuper.scala10
2 files changed, 12 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/core/NameOps.scala b/src/dotty/tools/dotc/core/NameOps.scala
index 593d5f036..cab47025e 100644
--- a/src/dotty/tools/dotc/core/NameOps.scala
+++ b/src/dotty/tools/dotc/core/NameOps.scala
@@ -167,6 +167,11 @@ object NameOps {
def expandedName(prefix: Name): N = expandedName(prefix, nme.EXPAND_SEPARATOR)
+ /** Revert the expanded name. Note: This currently gives incorrect results
+ * if the normal name contains `nme.EXPAND_SEPARATOR`, i.e. two consecutive '$'
+ * signs. This can happen for instance if a super accessor is paired with
+ * an encoded name, e.g. super$$plus$eq. See #765.
+ */
def unexpandedName: N = {
val idx = name.lastIndexOfSlice(nme.EXPAND_SEPARATOR)
if (idx < 0) name else (name drop (idx + nme.EXPAND_SEPARATOR.length)).asInstanceOf[N]
diff --git a/src/dotty/tools/dotc/transform/ResolveSuper.scala b/src/dotty/tools/dotc/transform/ResolveSuper.scala
index c699476bb..26128cf33 100644
--- a/src/dotty/tools/dotc/transform/ResolveSuper.scala
+++ b/src/dotty/tools/dotc/transform/ResolveSuper.scala
@@ -59,9 +59,13 @@ class ResolveSuper extends MiniPhaseTransform with IdentityDenotTransformer { th
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 originalAccName =
- if (acc.is(ExpandedName)) acc.name.unexpandedName else acc.name
- val SuperAccessorName(memberName) = originalAccName: Name // dotty deviation: ": Name" needed otherwise pattern type is neither a subtype nor a supertype of selector type
+ 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)