Skip to content

Commit ecfc9ef

Browse files
authored
Merge pull request #3491 from dotty-staging/fix-#3480
Fix #3480: Fix expanded name
2 parents 4fefb64 + 0c01501 commit ecfc9ef

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,12 @@ object NameOps {
114114
else name.toTermName.exclude(AvoidClashName)
115115
}
116116

117-
def expandedName(base: Symbol, kind: QualifiedNameKind = ExpandedName)(implicit ctx: Context): N = {
118-
val prefix =
119-
if (base.name.is(ExpandedName)) base.name else base.fullNameSeparated(ExpandPrefixName)
120-
likeSpaced { kind(prefix.toTermName, name.toTermName) }
121-
}
117+
/** The expanded name.
118+
* This is the fully qualified name of `base` with `ExpandPrefixName` as separator,
119+
* followed by `kind` and the name.
120+
*/
121+
def expandedName(base: Symbol, kind: QualifiedNameKind = ExpandedName)(implicit ctx: Context): N =
122+
likeSpaced { base.fullNameSeparated(ExpandPrefixName, kind, name) }
122123

123124
/** Revert the expanded name. */
124125
def unexpandedName: N = likeSpaced {

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -391,18 +391,23 @@ object SymDenotations {
391391
* Drops package objects. Represents each term in the owner chain by a simple `_$`.
392392
*/
393393
def fullNameSeparated(kind: QualifiedNameKind)(implicit ctx: Context): Name =
394-
if (symbol == NoSymbol ||
395-
owner == NoSymbol ||
396-
owner.isEffectiveRoot ||
397-
kind == FlatName && owner.is(PackageClass)) name
394+
maybeOwner.fullNameSeparated(kind, kind, name)
395+
396+
/** The encoded full path name of this denotation (separated by `prefixKind`),
397+
* followed by the separator implied by `kind` and the given `name`.
398+
* Drops package objects. Represents each term in the owner chain by a simple `_$`.
399+
*/
400+
def fullNameSeparated(prefixKind: QualifiedNameKind, kind: QualifiedNameKind, name: Name)(implicit ctx: Context): Name =
401+
if (symbol == NoSymbol || isEffectiveRoot || kind == FlatName && is(PackageClass))
402+
name
398403
else {
399404
var filler = ""
400-
var encl = owner
405+
var encl = symbol
401406
while (!encl.isClass && !encl.isPackageObject) {
402407
encl = encl.owner
403408
filler += "_$"
404409
}
405-
var prefix = encl.fullNameSeparated(kind)
410+
var prefix = encl.fullNameSeparated(prefixKind)
406411
if (kind.separator == "$")
407412
// duplicate scalac's behavior: don't write a double '$$' for module class members.
408413
prefix = prefix.exclude(ModuleClassName)
@@ -412,10 +417,9 @@ object SymDenotations {
412417
case name: SimpleName => qualify(name)
413418
case name @ AnyQualifiedName(_, _) => qualify(name.mangled.toSimpleName)
414419
}
415-
if (isType) fn.toTypeName else fn.toTermName
420+
if (name.isType) fn.toTypeName else fn.toTermName
416421
}
417422

418-
419423
/** The encoded flat name of this denotation, where joined names are separated by `separator` characters. */
420424
def flatName(implicit ctx: Context): Name = fullNameSeparated(FlatName)
421425

tests/pos/i3480.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Test {
2+
def foo(x: PartialFunction[Int, Int]) = x(0)
3+
4+
foo({ case i => i})
5+
}

tests/run/i3006b.check

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Foo$$init$$$bar$1
2-
Foo$$init$$$bar$2
3-
Bar$$init$$$bar$1
1+
Foo$$_$bar$1
2+
Foo$$_$bar$2
3+
Bar$$_$bar$1

0 commit comments

Comments
 (0)