File tree 2 files changed +15
-6
lines changed
compiler/src/dotty/tools/dotc
2 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -146,7 +146,9 @@ object Names {
146
146
def startsWith (str : String , start : Int = 0 ): Boolean = firstPart.startsWith(str, start)
147
147
148
148
/** Does (the last part of) this name end with `str`? */
149
- def endsWith (str : String ): Boolean = lastPart.endsWith(str)
149
+ def endsWith (suffix : String ): Boolean = lastPart.endsWith(suffix)
150
+
151
+ def endsWith (suffix : SimpleName ): Boolean = lastPart.endsWith(suffix)
150
152
151
153
override def hashCode : Int = System .identityHashCode(this )
152
154
override def equals (that : Any ): Boolean = this eq that.asInstanceOf [AnyRef ]
@@ -363,11 +365,15 @@ object Names {
363
365
i == str.length
364
366
}
365
367
366
- override def endsWith (str : String ): Boolean = {
368
+ override def endsWith (suffix : String ): Boolean =
367
369
var i = 1
368
- while (i <= str.length && i <= length && apply(length - i) == str(str.length - i)) i += 1
369
- i > str.length
370
- }
370
+ while i <= suffix.length && i <= length && apply(length - i) == suffix(suffix.length - i) do i += 1
371
+ i > suffix.length
372
+
373
+ override def endsWith (suffix : SimpleName ): Boolean =
374
+ var i = 1
375
+ while i <= suffix.length && i <= length && apply(length - i) == suffix(suffix.length - i) do i += 1
376
+ i > suffix.length
371
377
372
378
override def replace (from : Char , to : Char ): SimpleName = {
373
379
val cs = new Array [Char ](length)
Original file line number Diff line number Diff line change @@ -216,7 +216,10 @@ class Typer extends Namer
216
216
val termName = name.toTermName
217
217
218
218
def adjustExtension (name : Name ) =
219
- if required.is(Extension ) then name.toExtensionName else name
219
+ if required.is(Extension ) && termName.endsWith(name.lastPart)
220
+ // pre-check to avoid forming a new string; form extension only if it has a chance of matching `termName`
221
+ then name.toExtensionName
222
+ else name
220
223
221
224
def recur (selectors : List [untpd.ImportSelector ]): Type = selectors match
222
225
case selector :: rest =>
You can’t perform that action at this time.
0 commit comments