From 3197fe5de1ed3cb6cf57d88a406ea61c8638fbb7 Mon Sep 17 00:00:00 2001 From: "Paolo G. Giarrusso" Date: Mon, 27 Aug 2018 20:03:41 +0200 Subject: [PATCH] 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! --- compiler/src/dotty/tools/dotc/core/Decorators.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/core/Decorators.scala b/compiler/src/dotty/tools/dotc/core/Decorators.scala index 5da5cc8bd9e0..4343d2bb0ad9 100644 --- a/compiler/src/dotty/tools/dotc/core/Decorators.scala +++ b/compiler/src/dotty/tools/dotc/core/Decorators.scala @@ -157,7 +157,7 @@ object Decorators { names exists { name => name == "all" || { val strippedName = name.stripSuffix("+") - val logNextPhase = name ne strippedName + val logNextPhase = name != strippedName phase.phaseName.startsWith(strippedName) || (logNextPhase && phase.prev.phaseName.startsWith(strippedName)) }