Skip to content
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

Fix 2 bugs in the codegen for pattern matches #2955

Merged
merged 2 commits into from May 20, 2017

Conversation

sjrd
Copy link
Member

@sjrd sjrd commented May 19, 2017

No description provided.

For some reason, for such a snippet, the `Return` node directly
wraps the `LabelDef(matchEnd)`, rather than the `Block` surrounding
the entire translated pattern match.
@sjrd sjrd requested a review from gzm0 May 19, 2017 15:02
@scala-jenkins
Copy link

Refer to this link for build results (access rights to CI server needed):

https://scala-webapps.epfl.ch/jenkins/job/scalajs-pr/3964/
https://scala-webapps.epfl.ch/jenkins/job/scalajs-matrix-build/5251/
Test PASSed.

@@ -2955,9 +2960,10 @@ abstract class GenJSCode extends plugins.PluginComponent
translateMatch(expr)

// Sometimes the pattern matcher casts its final result
case Apply(TypeApply(Select(expr: LabelDef, nme.asInstanceOf_Ob), _), _)
case Apply(TypeApply(Select(expr: LabelDef, nme.asInstanceOf_Ob), targs), _)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you replace targs by List(targ) just to be extra prudent? (maybe also the last _ by Nil)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

In fe887a9, we added some code to
recognize shapes of pattern matches where the `expr` is a cast
surrounding the `matchEnd`. However, that code forgot to actually
translate the cast itself, yielding untypeable code. This commit
fixes that omission.
@scala-jenkins
Copy link

Refer to this link for build results (access rights to CI server needed):

https://scala-webapps.epfl.ch/jenkins/job/scalajs-pr/3970/
https://scala-webapps.epfl.ch/jenkins/job/scalajs-matrix-build/5259/
Test PASSed.

@sjrd sjrd merged commit bb2a55b into scala-js:0.6.x May 20, 2017
@sjrd sjrd deleted the fix-patmat-codegen branch May 20, 2017 17:11
@Test def return_x_match_issue_2928(): Unit = {
def testNonUnit(x: String): Boolean = {
return x match {
case "True" => true
Copy link
Contributor

Choose a reason for hiding this comment

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

@sjrd note that on Scala 2.13.8, matching on a String like this doesn't result in the weird Return(LabelDef(...)) tree — instead you get a normal Return(Match(...) tree, because matching on string constants is now handled differently. I think the PR when this changed is scala/scala#8451 ? So if you want this to actually be testing the change on Scala 2.13, I think you need to e.g. change x: String to x: AnyRef.

I hit this when trying to fix the same bug in my Fortify plugin.

Copy link
Member Author

@sjrd sjrd Jul 15, 2022

Choose a reason for hiding this comment

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

Ah, good catch! We should change the test to use some other data type.

The good news is that this problem will be entirely gone in 2.13.9+, thanks to scala/scala#10028

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, that's good to know 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Eh eh, looks like we already added a test for that when we added support for Match nodes with strings in
24a22d1
I tried to unfix the fix and it does crash on that test case in 2.13.8.

No idea how I thought about that when I made that commit. 😅

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.

None yet

4 participants