Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e9a54e5

Browse files
Revert "fix: do not transform Ident to This in PostTyper anymore" (#24059)
Reverts #23899 Related to #23875, #23999
2 parents 7864ebb + 01eab3b commit e9a54e5

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

‎compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,13 @@ object PatternMatcher {
482482
onSuccess
483483
)
484484
}
485-
case WildcardPattern() =>
485+
// When match against a `this.type` (say case a: this.type => ???),
486+
// the typer will transform the pattern to a `Bind(..., Typed(Ident(a), ThisType(...)))`,
487+
// then post typer will change all the `Ident` with a `ThisType` to a `This`.
488+
// Therefore, after pattern matching, we will have the following tree `Bind(..., Typed(This(...), ThisType(...)))`.
489+
// We handle now here the case were the pattern was transformed to a `This`, relying on the fact that the logic for
490+
// `Typed` above will create the correct type test.
491+
case WildcardPattern() | This(_) =>
486492
onSuccess
487493
case SeqLiteral(pats, _) =>
488494
matchElemsPlan(scrutinee, pats, exact = true, onSuccess)

‎compiler/src/dotty/tools/dotc/transform/PostTyper.scala‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,11 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase =>
391391
checkNotPackage(tree)
392392
else
393393
registerNeedsInlining(tree)
394-
checkUsableAsValue(tree)
394+
val tree1 = checkUsableAsValue(tree)
395+
tree1.tpe match {
396+
case tpe: ThisType => This(tpe.cls).withSpan(tree.span)
397+
case _ => tree1
398+
}
395399
case tree @ Select(qual, name) =>
396400
registerNeedsInlining(tree)
397401
if name.isTypeName then

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /