forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migration rewrites for infix arguments interpreted as named tuples (s…
…cala#21949) Best effort migration rewrites based on prior work in scala#21565 At this point, it's too late to deprecate named infix arguments. Let's produce warnings instead. We accept infix arguments that might be an argument of a named tuple, eg. `zip`, `++` or `==` - each of these takes a single argument with NamedTuple. --------- Co-authored-by: Som Snytt <[email protected]> Co-authored-by: Matt Bovel <[email protected]>
- Loading branch information
1 parent
7d2e869
commit 759d194
Showing
13 changed files
with
140 additions
and
6 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
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
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,41 @@ | ||
-- [E134] Type Error: tests/neg/infix-named-args.scala:2:13 ------------------------------------------------------------ | ||
2 | def f = 42 + (x = 1) // error // werror | ||
| ^^^^ | ||
| None of the overloaded alternatives of method + in class Int with types | ||
| (x: Double): Double | ||
| (x: Float): Float | ||
| (x: Long): Long | ||
| (x: Int): Int | ||
| (x: Char): Int | ||
| (x: Short): Int | ||
| (x: Byte): Int | ||
| (x: String): String | ||
| match arguments ((x : Int)) (a named tuple) | ||
-- [E204] Syntax Warning: tests/neg/infix-named-args.scala:2:15 -------------------------------------------------------- | ||
2 | def f = 42 + (x = 1) // error // werror | ||
| ^^^^^^^ | ||
|Ambigious syntax: this infix call argument list is interpreted as single named tuple argument, not as an named arguments list. | ||
|This can be rewritten automatically under -rewrite -source 3.6-migration. | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E204] Syntax Warning: tests/neg/infix-named-args.scala:5:26 -------------------------------------------------------- | ||
5 | def g = new C() `multi` (x = 42, y = 27) // werror | ||
| ^^^^^^^^^^^^^^^^ | ||
|Ambigious syntax: this infix call argument list is interpreted as single named tuple argument, not as an named arguments list. | ||
|This can be rewritten automatically under -rewrite -source 3.6-migration. | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E204] Syntax Warning: tests/neg/infix-named-args.scala:6:21 -------------------------------------------------------- | ||
6 | def h = new C() ** (x = 42, y = 27) // werror | ||
| ^^^^^^^^^^^^^^^^ | ||
|Ambigious syntax: this infix call argument list is interpreted as single named tuple argument, not as an named arguments list. | ||
|This can be rewritten automatically under -rewrite -source 3.6-migration. | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E204] Syntax Warning: tests/neg/infix-named-args.scala:13:18 ------------------------------------------------------- | ||
13 | def f = this ** (x = 2) // werror | ||
| ^^^^^^^ | ||
|Ambigious syntax: this infix call argument list is interpreted as single named tuple argument, not as an named arguments list. | ||
|This can be rewritten automatically under -rewrite -source 3.6-migration. | ||
| | ||
| longer explanation available when compiling with `-explain` |
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,14 @@ | ||
class C: | ||
def f = 42 + (x = 1) // error // werror | ||
def multi(x: Int, y: Int): Int = x + y | ||
def **(x: Int, y: Int): Int = x + y | ||
def g = new C() `multi` (x = 42, y = 27) // werror | ||
def h = new C() ** (x = 42, y = 27) // werror | ||
|
||
type X = (x: Int) | ||
|
||
class D(d: Int): | ||
def **(x: Int): Int = d * x | ||
def **(x: X): Int = d * x.x | ||
def f = this ** (x = 2) // werror | ||
def g = this ** 2 |
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,15 @@ | ||
class C: | ||
def multi(x: Int, y: Int): Int = x + y | ||
def **(x: Int, y: Int): Int = x + y | ||
def g = new C().multi(x = 42, y = 27) | ||
def h = new C().**(x = 42, y = 27) | ||
|
||
type X = (x: Int) | ||
|
||
class D(d: Int): | ||
def **(x: Int): Int = d * x | ||
def **(x: X): Int = d * x.x | ||
def f = this.**(x = 2) | ||
def g = this ** 2 | ||
def h = this ** ((x = 2)) | ||
def i = this.**(x = (1 + 1)) |
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,15 @@ | ||
class C: | ||
def multi(x: Int, y: Int): Int = x + y | ||
def **(x: Int, y: Int): Int = x + y | ||
def g = new C() `multi` (x = 42, y = 27) | ||
def h = new C() ** (x = 42, y = 27) | ||
|
||
type X = (x: Int) | ||
|
||
class D(d: Int): | ||
def **(x: Int): Int = d * x | ||
def **(x: X): Int = d * x.x | ||
def f = this ** (x = 2) | ||
def g = this ** 2 | ||
def h = this ** ((x = 2)) | ||
def i = this ** (x = (1 + 1)) |
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,14 @@ | ||
//> using options -source:3.6-migration | ||
class C: | ||
def f = 42 + (x = 1) // warn // interpreted as 42.+(x = 1) under migration, x is a valid synthetic parameter name | ||
def multi(x: Int, y: Int): Int = x + y | ||
def **(x: Int, y: Int): Int = x + y | ||
def g = new C() `multi` (x = 42, y = 27) // warn | ||
def h = new C() ** (x = 42, y = 27) // warn | ||
|
||
type X = (x: Int) | ||
|
||
class D(d: Int): | ||
def **(x: Int): Int = d * x | ||
def f = this ** (x = 2) // warn | ||
def g = this ** 2 |