-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate named patterns for case classes (#22242)
I found out that there is no validation happening for named patterns of case classes. https://scastie.scala-lang.org/W4p7RBrySwuteISEPuqSUw There were 2 different things that blocked the errors: 1. We actually did not run `checkWellFormedTupleElems` in that scenario, 2. We run `tryAdaptPatternArgs` in `tryEither` which has nested context that does not report errors which are not sticky.
- Loading branch information
Showing
4 changed files
with
44 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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 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 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,16 @@ | ||
-- Error: tests/neg/named-tuples-4.scala:10:35 ------------------------------------------------------------------------- | ||
10 | case PersonCaseClass(name = n, age) => () // error | ||
| ^^^ | ||
| Illegal combination of named and unnamed tuple elements | ||
-- Error: tests/neg/named-tuples-4.scala:11:31 ------------------------------------------------------------------------- | ||
11 | case PersonCaseClass(name, age = a) => () // error | ||
| ^^^^^^^ | ||
| Illegal combination of named and unnamed tuple elements | ||
-- Error: tests/neg/named-tuples-4.scala:15:20 ------------------------------------------------------------------------- | ||
15 | case (name = n, age) => () // error | ||
| ^^^ | ||
| Illegal combination of named and unnamed tuple elements | ||
-- Error: tests/neg/named-tuples-4.scala:16:16 ------------------------------------------------------------------------- | ||
16 | case (name, age = a) => () // error | ||
| ^^^^^^^ | ||
| Illegal combination of named and unnamed tuple elements |
This file contains 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,16 @@ | ||
import language.experimental.namedTuples | ||
import scala.annotation.experimental | ||
|
||
@experimental object Test: | ||
|
||
case class PersonCaseClass(name: String, age: Int) | ||
|
||
val personCaseClass = PersonCaseClass("Bob", 33) | ||
personCaseClass match | ||
case PersonCaseClass(name = n, age) => () // error | ||
case PersonCaseClass(name, age = a) => () // error | ||
|
||
val person = (name = "Bob", age = 33): (name: String, age: Int) | ||
person match | ||
case (name = n, age) => () // error | ||
case (name, age = a) => () // error |