@@ -147,9 +147,11 @@ class FirstTransform extends MiniPhase with InfoTransformer { thisPhase =>
147
147
if (tree.isType) {
148
148
toTypeTree(tree)
149
149
} 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.
153
155
constToLiteral(tree)
154
156
} else tree
155
157
@@ -163,8 +165,8 @@ class FirstTransform extends MiniPhase with InfoTransformer { thisPhase =>
163
165
constToLiteral(foldCondition(tree))
164
166
165
167
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).
168
170
if (! ctx.mode.is(Mode .Pattern )) constToLiteral(tree) else tree
169
171
170
172
override def transformBlock (tree : Block )(implicit ctx : Context ): Tree =
0 commit comments