Skip to content

Commit 4b64f0b

Browse files
committed
Make the comments clearer
1 parent 84b1f36 commit 4b64f0b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

compiler/src/dotty/tools/dotc/transform/FirstTransform.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)