-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #1846: add regression test #3810
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
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
18d0361
Fix #1846: add regression test
liufengyun 96afef1
add more tests
liufengyun 47256d2
Add Eq check for Apply tree in adapting patterns
liufengyun cff4826
Fix #3812: Refine tests for pattern match
allanrenucci 2734958
fix retyper in checking Select in patterns
liufengyun 0677c77
remove block syntax in patterns
liufengyun 2fe7940
check qualifier is stable in pattern select
liufengyun 798b0d3
remove noise in test code
liufengyun 77ac75c
revert the change to typer
liufengyun 4630203
address review: move check to typer
liufengyun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
object Test { | ||
def main(args: Array[String]): Unit = { | ||
val x = 42 | ||
val Y = "42" | ||
|
||
x match { case { 42 } => () } // error | ||
x match { case { 42.toString } => () } // error | ||
x match { case { 42 }.toString => () } // error | ||
x match { case "42".toInt => () } // error | ||
x match { case { "42".toInt } => () } // error | ||
x match { case { "42" }.toInt => () } // error | ||
x match { case { "42".toInt } => () } // error | ||
x match { case Y => () } // error | ||
x match { case { Y.toInt } => () } // error | ||
x match { case { Y }.toInt => () } // error | ||
x match { case { Y }.toString => () } // error | ||
x match { case { Y.toString } => () } // error | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
object Test { | ||
def main(args: Array[String]): Unit = { | ||
val x = 42 | ||
val Y = "42" | ||
|
||
x match { case { 42 } => () } // error | ||
x match { case { "42".toInt } => () } // error | ||
x match { case { "42" }.toInt => () } // error | ||
x match { case { "42".toInt } => () } // error | ||
x match { case { Y.toInt } => () } // error | ||
x match { case { Y }.toInt => () } // error | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
object Test { | ||
def main(args: Array[String]): Unit = { | ||
case class Box(v: Int) | ||
|
||
val x = 42 | ||
var Y1 = 42 | ||
val Y2 = "42" | ||
var Z1 = Box(4) | ||
val Z2 = Box(4) | ||
|
||
x match { case Y1 => () } // error | ||
x match { case Y2.toInt => () } // error | ||
x match { case Y1.toString => () } // error | ||
|
||
x match { case Z1.v => () } // error | ||
x match { case Z2.v => () } // ok | ||
|
||
Some(x) match { case Some(Z1.v) => () } // error | ||
Some(x) match { case Some(Z2.v) => () } // ok | ||
|
||
Some(x) match { case Some(4) | Some(Z1.v) => () } // error | ||
Some(x) match { case a @ Some(Z1.v) => () } // error | ||
|
||
Some(x) match { case Some(4) | Some(Z2.v) => () } // ok | ||
Some(x) match { case a @ Some(Z2.v) => () } // ok | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it would be simpler to put this check in Typer.
Here, we could just add
if (ctx.mode.is(Mode.Pattern) && !tree.tpe.isStable) error
to the checks for Ident and Select.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I am also no sure why we should demand stability? What would go wrong if we didn't?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following check seems too strong to me:
As a selection of
unapply
would fail this check. The check should only happen for Stable Identifier Pattern (SLS 8.1.5). I don't know what's the motivation for the Scala specification. Arguably, avar
could be allowed in a pattern, but then it complicates the specification and check.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, so let's keep the test for stable idents but move it to Typer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, now it's done.