-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Make singleton typecase patterns and type checks consistent #7027
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,9 +147,11 @@ class FirstTransform extends MiniPhase with InfoTransformer { thisPhase => | |
if (tree.isType) { | ||
toTypeTree(tree) | ||
} else if (tree.name != nme.WILDCARD) { | ||
// We want to constant-fold _some_ idents here - for instance, @switch needs to see literals in patterns. | ||
// However, constant-foldable wildcards can occur in patterns, for instance as `case _: "a"`; | ||
// we avoid constant-folding those as doing so would change the meaning of the pattern. | ||
// We constant-fold all idents except wildcards. | ||
// AFAIK, constant-foldable wildcard idents can only occur in patterns, for instance as `case _: "a"`. | ||
// Constant-folding that would result in `case "a": "a"`, which changes the meaning of the pattern. | ||
// Note that we _do_ want to constant-fold idents in patterns that _aren't_ wildcards - | ||
// for example, @switch annotation needs to see inlined literals and not indirect references. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @smarter I think this comment is at the precise level of detail that we want. I don't think going into the subtle differences of Bind/Ident nodes in patterns makes sense - if we did that consequently in the whole compiler, then more than half of the documentation would be permanently outdated. |
||
constToLiteral(tree) | ||
} else tree | ||
|
||
|
@@ -163,8 +165,8 @@ class FirstTransform extends MiniPhase with InfoTransformer { thisPhase => | |
constToLiteral(foldCondition(tree)) | ||
|
||
override def transformTyped(tree: Typed)(implicit ctx: Context): Tree = | ||
// Singleton type cases (such as `case _: "a"`) are constant-foldable | ||
// we avoid constant-folding those as doing so would change the meaning of the pattern | ||
// Singleton type cases (such as `case _: "a"`) are constant-foldable. | ||
// We avoid constant-folding those as doing so would change the meaning of the pattern (see transformIdent). | ||
if (!ctx.mode.is(Mode.Pattern)) constToLiteral(tree) else tree | ||
|
||
override def transformBlock(tree: Block)(implicit ctx: Context): Tree = | ||
|
Uh oh!
There was an error while loading. Please reload this page.