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 @@ -482,7 +482,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
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/PostTyper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,11 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase =>
checkNotPackage(tree)
else
registerNeedsInlining(tree)
checkUsableAsValue(tree)
val tree1 = checkUsableAsValue(tree)
tree1.tpe match {
case tpe: ThisType => This(tpe.cls).withSpan(tree.span)
case _ => tree1
}
case tree @ Select(qual, name) =>
registerNeedsInlining(tree)
if name.isTypeName then
Expand Down
Loading