@@ -147,9 +147,11 @@ class FirstTransform extends MiniPhase with InfoTransformer { thisPhase =>
147147 if (tree.isType) {
148148 toTypeTree(tree)
149149 } else if (tree.name != nme.WILDCARD ) {
150- // We want to constant-fold _some_ idents here - for instance, @switch needs to see literals in patterns.
151- // However, constant-foldable wildcards can occur in patterns, for instance as `case _: "a"`;
152- // we avoid constant-folding those as doing so would change the meaning of the pattern.
150+ // We constant-fold all idents except wildcards.
151+ // AFAIK, constant-foldable wildcard idents can only occur in patterns, for instance as `case _: "a"`.
152+ // Constant-folding that would result in `case "a": "a"`, which changes the meaning of the pattern.
153+ // Note that we _do_ want to constant-fold idents in patterns that _aren't_ wildcards -
154+ // for example, @switch annotation needs to see inlined literals and not indirect references.
153155 constToLiteral(tree)
154156 } else tree
155157
@@ -163,8 +165,8 @@ class FirstTransform extends MiniPhase with InfoTransformer { thisPhase =>
163165 constToLiteral(foldCondition(tree))
164166
165167 override def transformTyped (tree : Typed )(implicit ctx : Context ): Tree =
166- // Singleton type cases (such as `case _: "a"`) are constant-foldable
167- // we avoid constant-folding those as doing so would change the meaning of the pattern
168+ // Singleton type cases (such as `case _: "a"`) are constant-foldable.
169+ // We avoid constant-folding those as doing so would change the meaning of the pattern (see transformIdent).
168170 if (! ctx.mode.is(Mode .Pattern )) constToLiteral(tree) else tree
169171
170172 override def transformBlock (tree : Block )(implicit ctx : Context ): Tree =
0 commit comments