Skip to content

Commit 5b045ae

Browse files
Backport "Revert "fix: do not transform Ident to This in PostTyper anymore"" to 3.7.4 (#24065)
Backports #24059 to the 3.7.4. PR submitted by the release tooling.
2 parents 473e78e + d9658a2 commit 5b045ae

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

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

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

tests/run/i23875.check

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
true
2+
false
3+
false

tests/run/i23875.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
object Foo {
2+
override def equals(that : Any) = that match {
3+
case _: this.type => true
4+
case _ => false
5+
}
6+
}
7+
8+
@main def Test =
9+
println(Foo.equals(Foo))
10+
println(Foo.equals(new AnyRef {}))
11+
println(Foo.equals(0))

0 commit comments

Comments
 (0)