Skip to content

Type match with a match type when a match type is expected #15599

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

Merged
merged 1 commit into from
Oct 3, 2022

Conversation

mbovel
Copy link
Member

@mbovel mbovel commented Jul 6, 2022

No description provided.

@mbovel mbovel requested a review from OlivierBlanvillain July 6, 2022 10:46
@mbovel mbovel marked this pull request as draft July 6, 2022 10:47
@mbovel mbovel force-pushed the mb/match-types-result branch from 45e971f to 2017b87 Compare July 6, 2022 10:56
@mbovel
Copy link
Member Author

mbovel commented Jul 6, 2022

Alternative implementation: could also add a case here instead of modifying MatchTypeInDisguise:

diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala
index e4aa1e634e..bd99da7b0e 100644
--- a/compiler/src/dotty/tools/dotc/typer/Typer.scala
+++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala
@@ -1601,6 +1601,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
         val result = pt match {
           case MatchTypeInDisguise(mt) if isMatchTypeShaped(mt) =>
             typedDependentMatchFinish(tree, sel1, selType, tree.cases, mt)
+          case mt: MatchType if isMatchTypeShaped(mt) =>
+            typedDependentMatchFinish(tree, sel1, selType, tree.cases, mt)
           case _ =>
             typedMatchFinish(tree, sel1, selType, tree.cases, pt)
         }

@mbovel mbovel marked this pull request as ready for review July 6, 2022 12:36
Copy link
Contributor

@OlivierBlanvillain OlivierBlanvillain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@bishabosha
Copy link
Member

Alternative implementation: could also add a case here instead of modifying MatchTypeInDisguise:

I think I would prefer that one because now all all types will be tested by MatchTypeInDisguise, which I guess can alter the pattern match plan of all the existing call-sites, but only a benchmark can know the impact.

@mbovel mbovel force-pushed the mb/match-types-result branch from 2017b87 to e4cb7b8 Compare October 3, 2022 13:03
@mbovel
Copy link
Member Author

mbovel commented Oct 3, 2022

Alternative implementation: could also add a case here instead of modifying MatchTypeInDisguise:

I think I would prefer that one because now all all types will be tested by MatchTypeInDisguise, which I guess can alter the pattern match plan of all the existing call-sites, but only a benchmark can know the impact.

Ok, I changed from adding a case mt: MatchType => Some(mt) inside MatchType.InDisguise to adding a case mt: MatchType if isMatchTypeShaped(mt) in Typer.typedMatch.

@mbovel mbovel requested a review from bishabosha October 3, 2022 14:27
@mbovel mbovel merged commit c574f31 into scala:main Oct 3, 2022
@mbovel mbovel deleted the mb/match-types-result branch October 3, 2022 15:05
@Kordyjan Kordyjan added this to the 3.2.2 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants