Skip to content

Commit 3197fe5

Browse files
authored
Avoid fishy reference equality on strings
While the code looks correct (because strippedName comes from stripSuffix and because of stripSuffix's contract and implementation), this is subtle enough that we should either add a test or use !=. Since `String.equals` happens to be O(1) in this case, changing the code looks simpler. `String.equals` is O(1) here because it will either succeed by testing pointer equality or fail by noticing a length mismatch, so it will never look at the actual contents!
1 parent 973b675 commit 3197fe5

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ object Decorators {
157157
names exists { name =>
158158
name == "all" || {
159159
val strippedName = name.stripSuffix("+")
160-
val logNextPhase = name ne strippedName
160+
val logNextPhase = name != strippedName
161161
phase.phaseName.startsWith(strippedName) ||
162162
(logNextPhase && phase.prev.phaseName.startsWith(strippedName))
163163
}

0 commit comments

Comments
 (0)