Skip to content

Fix #3480: Fix expanded name #3491

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 1 commit into from
Nov 20, 2017
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
11 changes: 6 additions & 5 deletions compiler/src/dotty/tools/dotc/core/NameOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 12 additions & 8 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down
5 changes: 5 additions & 0 deletions tests/pos/i3480.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Test {
def foo(x: PartialFunction[Int, Int]) = x(0)

foo({ case i => i})
}
6 changes: 3 additions & 3 deletions tests/run/i3006b.check
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Foo$$init$$$bar$1
Foo$$init$$$bar$2
Bar$$init$$$bar$1
Foo$$_$bar$1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this changed? Isn't this going to make debugging more difficult?

Copy link
Contributor Author

@odersky odersky Nov 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes things more regular. Fully qualified names in general represent terms in the owner chain with "_$". The problem was that we treated the last separator of an expanded name as different from the others. This looks wrong. It's a different question what fully qualified names should do to represent term owners in the chain. AFAIK scalac skips them completely.

Foo$$_$bar$2
Bar$$_$bar$1