diff --git a/compiler/src/dotty/tools/dotc/core/NameOps.scala b/compiler/src/dotty/tools/dotc/core/NameOps.scala index 4e568861e401..b1c618a15a50 100644 --- a/compiler/src/dotty/tools/dotc/core/NameOps.scala +++ b/compiler/src/dotty/tools/dotc/core/NameOps.scala @@ -114,11 +114,12 @@ object NameOps { else name.toTermName.exclude(AvoidClashName) } - def expandedName(base: Symbol, kind: QualifiedNameKind = ExpandedName)(implicit ctx: Context): N = { - val prefix = - if (base.name.is(ExpandedName)) base.name else base.fullNameSeparated(ExpandPrefixName) - likeSpaced { kind(prefix.toTermName, name.toTermName) } - } + /** The expanded name. + * This is the fully qualified name of `base` with `ExpandPrefixName` as separator, + * followed by `kind` and the name. + */ + def expandedName(base: Symbol, kind: QualifiedNameKind = ExpandedName)(implicit ctx: Context): N = + likeSpaced { base.fullNameSeparated(ExpandPrefixName, kind, name) } /** Revert the expanded name. */ def unexpandedName: N = likeSpaced { diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index 145913261053..1703a0c834ff 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -391,18 +391,23 @@ object SymDenotations { * Drops package objects. Represents each term in the owner chain by a simple `_$`. */ def fullNameSeparated(kind: QualifiedNameKind)(implicit ctx: Context): Name = - if (symbol == NoSymbol || - owner == NoSymbol || - owner.isEffectiveRoot || - kind == FlatName && owner.is(PackageClass)) name + maybeOwner.fullNameSeparated(kind, kind, name) + + /** The encoded full path name of this denotation (separated by `prefixKind`), + * followed by the separator implied by `kind` and the given `name`. + * Drops package objects. Represents each term in the owner chain by a simple `_$`. + */ + def fullNameSeparated(prefixKind: QualifiedNameKind, kind: QualifiedNameKind, name: Name)(implicit ctx: Context): Name = + if (symbol == NoSymbol || isEffectiveRoot || kind == FlatName && is(PackageClass)) + name else { var filler = "" - var encl = owner + var encl = symbol while (!encl.isClass && !encl.isPackageObject) { encl = encl.owner filler += "_$" } - var prefix = encl.fullNameSeparated(kind) + var prefix = encl.fullNameSeparated(prefixKind) if (kind.separator == "$") // duplicate scalac's behavior: don't write a double '$$' for module class members. prefix = prefix.exclude(ModuleClassName) @@ -412,10 +417,9 @@ object SymDenotations { case name: SimpleName => qualify(name) case name @ AnyQualifiedName(_, _) => qualify(name.mangled.toSimpleName) } - if (isType) fn.toTypeName else fn.toTermName + if (name.isType) fn.toTypeName else fn.toTermName } - /** The encoded flat name of this denotation, where joined names are separated by `separator` characters. */ def flatName(implicit ctx: Context): Name = fullNameSeparated(FlatName) diff --git a/tests/pos/i3480.scala b/tests/pos/i3480.scala new file mode 100644 index 000000000000..05aa5ecf3f07 --- /dev/null +++ b/tests/pos/i3480.scala @@ -0,0 +1,5 @@ +class Test { + def foo(x: PartialFunction[Int, Int]) = x(0) + + foo({ case i => i}) +} diff --git a/tests/run/i3006b.check b/tests/run/i3006b.check index 78405f03836c..b62605500d51 100644 --- a/tests/run/i3006b.check +++ b/tests/run/i3006b.check @@ -1,3 +1,3 @@ -Foo$$init$$$bar$1 -Foo$$init$$$bar$2 -Bar$$init$$$bar$1 +Foo$$_$bar$1 +Foo$$_$bar$2 +Bar$$_$bar$1