Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,13 @@ object PatternMatcher {
onSuccess
)
}
case WildcardPattern() =>
// When match against a `this.type` (say case a: this.type => ???),
// the typer will transform the pattern to a `Bind(..., Typed(Ident(a), ThisType(...)))`,
// then post typer will change all the `Ident` with a `ThisType` to a `This`.
// Therefore, after pattern matching, we will have the following tree `Bind(..., Typed(This(...), ThisType(...)))`.
// We handle now here the case were the pattern was transformed to a `This`, relying on the fact that the logic for
// `Typed` above will create the correct type test.
case WildcardPattern() | This(_) =>
onSuccess
case SeqLiteral(pats, _) =>
matchElemsPlan(scrutinee, pats, exact = true, onSuccess)
Expand Down
3 changes: 3 additions & 0 deletions tests/run/i23875.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
true
false
false
11 changes: 11 additions & 0 deletions tests/run/i23875.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
object Foo {
override def equals(that : Any) = that match {
case _: this.type => true
case _ => false
}
}

@main def Test =
println(Foo.equals(Foo))
println(Foo.equals(new AnyRef {}))
println(Foo.equals(0))
Loading