Skip to content

Commit 600293e

Browse files
committed
FIX: Allow ContextBoundParamNames to be unmangled.
Also, fix the unmangling of UniqueExtNames, which seemingly never worked.
1 parent b48fb99 commit 600293e

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

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

+17-20
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,13 @@ object NameKinds {
182182
case DerivedName(underlying, info: this.NumberedInfo) => Some((underlying, info.num))
183183
case _ => None
184184
}
185-
protected def skipSeparatorAndNum(name: SimpleName, separator: String): Int = {
185+
protected def skipSeparatorAndNum(name: SimpleName, separator: String): Int =
186186
var i = name.length
187-
while (i > 0 && name(i - 1).isDigit) i -= 1
188-
if (i > separator.length && i < name.length &&
189-
name.slice(i - separator.length, i).toString == separator) i
187+
while i > 0 && name(i - 1).isDigit do i -= 1
188+
if i >= separator.length && i < name.length
189+
&& name.slice(i - separator.length, i).toString == separator
190+
then i
190191
else -1
191-
}
192192

193193
numberedNameKinds(tag) = this: @unchecked
194194
}
@@ -240,6 +240,16 @@ object NameKinds {
240240
}
241241
}
242242

243+
/** Unique names that can be unmangled */
244+
class UniqueNameKindWithUnmangle(separator: String) extends UniqueNameKind(separator):
245+
override def unmangle(name: SimpleName): TermName =
246+
val i = skipSeparatorAndNum(name, separator)
247+
if i > 0 then
248+
val index = name.drop(i).toString.toInt
249+
val original = name.take(i - separator.length).asTermName
250+
apply(original, index)
251+
else name
252+
243253
/** Names of the form `prefix . name` */
244254
val QualifiedName: QualifiedNameKind = new QualifiedNameKind(QUALIFIED, ".")
245255

@@ -288,7 +298,7 @@ object NameKinds {
288298
*
289299
* The "evidence$" prefix is a convention copied from Scala 2.
290300
*/
291-
val ContextBoundParamName: UniqueNameKind = new UniqueNameKind("evidence$")
301+
val ContextBoundParamName: UniqueNameKind = new UniqueNameKindWithUnmangle("evidence$")
292302

293303
/** The name of an inferred contextual function parameter:
294304
*
@@ -323,20 +333,7 @@ object NameKinds {
323333
val InlineBinderName: UniqueNameKind = new UniqueNameKind("$proxy")
324334
val MacroNames: UniqueNameKind = new UniqueNameKind("$macro$")
325335

326-
/** A kind of unique extension methods; Unlike other unique names, these can be
327-
* unmangled.
328-
*/
329-
val UniqueExtMethName: UniqueNameKind = new UniqueNameKind("$extension") {
330-
override def unmangle(name: SimpleName): TermName = {
331-
val i = skipSeparatorAndNum(name, separator)
332-
if (i > 0) {
333-
val index = name.drop(i).toString.toInt
334-
val original = name.take(i - separator.length).asTermName
335-
apply(original, index)
336-
}
337-
else name
338-
}
339-
}
336+
val UniqueExtMethName: UniqueNameKind = new UniqueNameKindWithUnmangle("$extension")
340337

341338
/** Kinds of unique names generated by the pattern matcher */
342339
val PatMatStdBinderName: UniqueNameKind = new UniqueNameKind("x")

0 commit comments

Comments
 (0)