From 9f4871bb4bd522fd39ee063425620b9ccee48946 Mon Sep 17 00:00:00 2001 From: odersky Date: Thu, 21 Jul 2022 11:48:02 +0200 Subject: [PATCH] Clean up logic using a new method `replaceDeep` --- compiler/src/dotty/tools/dotc/core/NameOps.scala | 3 +-- compiler/src/dotty/tools/dotc/core/Names.scala | 9 ++++++++- .../src/dotty/tools/dotc/core/SymDenotations.scala | 11 +++-------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/NameOps.scala b/compiler/src/dotty/tools/dotc/core/NameOps.scala index 39df940fe700..98fcf0d9e303 100644 --- a/compiler/src/dotty/tools/dotc/core/NameOps.scala +++ b/compiler/src/dotty/tools/dotc/core/NameOps.scala @@ -146,9 +146,8 @@ object NameOps { /** Revert the expanded name. */ def unexpandedName: N = likeSpacedN { - name.replace { + name.replaceDeep { case ExpandedName(_, unexp) => unexp - case DerivedName(qual, info: QualifiedInfo) => qual.unexpandedName.derived(info) } } diff --git a/compiler/src/dotty/tools/dotc/core/Names.scala b/compiler/src/dotty/tools/dotc/core/Names.scala index b1e8da359407..f13c3a184bf9 100644 --- a/compiler/src/dotty/tools/dotc/core/Names.scala +++ b/compiler/src/dotty/tools/dotc/core/Names.scala @@ -69,11 +69,18 @@ object Names { /** Apply rewrite rule given by `f` to some part of this name, skipping and rewrapping * other decorators. - * Stops at `DerivedName`s with infos of kind `QualifiedInfo`. + * Stops at DerivedNames with infos of kind QualifiedInfo. * If `f` does not apply to any part, return name unchanged. */ def replace(f: PartialFunction[Name, Name]): ThisName + /** Same as replace, but does not stop at DerivedNames with infos of kind QualifiedInfo. */ + def replaceDeep(f: PartialFunction[Name, Name]): ThisName = + replace(f.orElse { + case DerivedName(underlying, info: QualifiedInfo) => + underlying.replaceDeep(f).derived(info) + }) + /** If partial function `f` is defined for some part of this name, apply it * in a Some, otherwise None. * Stops at derived names whose kind has `definesNewName = true`. diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index 53a71390124a..a1752ccc0976 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -486,15 +486,10 @@ object SymDenotations { def qualify(n: SimpleName) = val qn = kind(prefix.toTermName, if (filler.isEmpty) n else termName(filler + n)) if kind == FlatName && !encl.is(JavaDefined) then qn.compactified else qn - def expand(name: Name): Name = name.replace { - case name: SimpleName => qualify(name) - case name @ DerivedName(qual, info: QualifiedInfo) => - expand(qual).derived(info) - // Keep the qualified name, so that it can be recovered later. - // An example where this matters is run/i15702.scala + val fn = name.replaceDeep { + case n: SimpleName => qualify(n) } - val fn = expand(name) - if (name.isTypeName) fn.toTypeName else fn.toTermName + if name.isTypeName then fn.toTypeName else fn.toTermName } /** The encoded flat name of this denotation, where joined names are separated by `separator` characters. */