Skip to content

Commit 6159045

Browse files
committed
Simplify erased parameter syntax
erased is not always a modifier on the parameter name. The syntax `erased Type` is dropped. There's not really a need for this syntactic inconsistency.
1 parent 6a9bea8 commit 6159045

6 files changed

+21
-21
lines changed

Diff for: compiler/src/dotty/tools/dotc/parsing/Parsers.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1631,7 +1631,7 @@ object Parsers {
16311631
() => funParam(in.offset, imods))
16321632
case t =>
16331633
def funArg() =
1634-
addErased()
1634+
erasedArgs.addOne(false)
16351635
funArgType()
16361636
commaSeparatedRest(t, funArg)
16371637
accept(RPAREN)

Diff for: tests/neg/lambda-infer.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//> using options -language:experimental.erasedDefinitions
22

3-
type F = (Int, erased Int) => Int
3+
type F = (x: Int, erased y: Int) => Int
44

55
erased class A
66

@@ -14,7 +14,7 @@ erased class A
1414

1515
use { (x, y) => x } // error: Expected F got (Int, Int) => Int
1616

17-
def singleParam(f: (erased Int) => Int) = f(5)
17+
def singleParam(f: (erased x: Int) => Int) = f(5)
1818

1919
singleParam(x => 5) // error: Expected (erased Int) => Int got Int => Int
2020
singleParam((erased x) => 5) // ok

Diff for: tests/neg/polymorphic-erased-functions-types.check

+10-10
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
| Required: [T] => (x$1: T) => Unit
66
|
77
| longer explanation available when compiling with `-explain`
8-
-- [E007] Type Mismatch Error: tests/neg/polymorphic-erased-functions-types.scala:4:37 ---------------------------------
9-
4 |def t1b: [T] => (erased T) => Unit = [T] => (t: T) => () // error
10-
| ^^^^^^^^^^^^^^^^^^^
11-
| Found: [T] => (t: T) => Unit
12-
| Required: [T] => (erased x$1: T) => Unit
8+
-- [E007] Type Mismatch Error: tests/neg/polymorphic-erased-functions-types.scala:4:40 ---------------------------------
9+
4 |def t1b: [T] => (erased t: T) => Unit = [T] => (t: T) => () // error
10+
| ^^^^^^^^^^^^^^^^^^^
11+
| Found: [T] => (t: T) => Unit
12+
| Required: [T] => (erased t: T) => Unit
1313
|
1414
| longer explanation available when compiling with `-explain`
1515
-- [E007] Type Mismatch Error: tests/neg/polymorphic-erased-functions-types.scala:6:36 ---------------------------------
@@ -19,10 +19,10 @@
1919
| Required: [T, U] => (x$1: T, x$2: U) => Unit
2020
|
2121
| longer explanation available when compiling with `-explain`
22-
-- [E007] Type Mismatch Error: tests/neg/polymorphic-erased-functions-types.scala:7:43 ---------------------------------
23-
7 |def t2b: [T, U] => (T, erased U) => Unit = [T, U] => (t: T, u: U) => () // error
24-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25-
| Found: [T, U] => (t: T, u: U) => Unit
26-
| Required: [T, U] => (x$1: T, erased x$2: U) => Unit
22+
-- [E007] Type Mismatch Error: tests/neg/polymorphic-erased-functions-types.scala:7:49 ---------------------------------
23+
7 |def t2b: [T, U] => (t: T, erased u: U) => Unit = [T, U] => (t: T, u: U) => () // error
24+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25+
| Found: [T, U] => (t: T, u: U) => Unit
26+
| Required: [T, U] => (t: T, erased u: U) => Unit
2727
|
2828
| longer explanation available when compiling with `-explain`

Diff for: tests/neg/polymorphic-erased-functions-types.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import language.experimental.erasedDefinitions
22

33
def t1a: [T] => T => Unit = [T] => (erased t: T) => () // error
4-
def t1b: [T] => (erased T) => Unit = [T] => (t: T) => () // error
4+
def t1b: [T] => (erased t: T) => Unit = [T] => (t: T) => () // error
55

66
def t2a: [T, U] => (T, U) => Unit = [T, U] => (t: T, erased u: U) => () // error
7-
def t2b: [T, U] => (T, erased U) => Unit = [T, U] => (t: T, u: U) => () // error
7+
def t2b: [T, U] => (t: T, erased u: U) => Unit = [T, U] => (t: T, u: U) => () // error

Diff for: tests/run/erased-lambdas.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
// lambdas should parse and work
55

6-
type F = (erased Int, String) => String
7-
type S = (Int, erased String) => Int
6+
type F = (erased x: Int, y: String) => String
7+
type S = (x: Int, erased y: String) => Int
88

99
def useF(f: F) = f(5, "a")
1010
def useS(f: S) = f(5, "a")
@@ -16,7 +16,7 @@ val fsExpl = (x: Int, erased y: String) => x
1616

1717
// contextual lambdas should work
1818

19-
type FC = (Int, erased String) ?=> Int
19+
type FC = (x: Int, erased y: String) ?=> Int
2020

2121
def useCtx(f: FC) = f(using 5, "a")
2222

@@ -25,7 +25,7 @@ val fCvExpl = (x: Int, erased y: String) ?=> x
2525

2626
// nested lambdas should work
2727

28-
val nested: Int => (String, erased Int) => FC = a => (_, erased _) => (c, erased d) ?=> a + c
28+
val nested: Int => (x: String, erased y: Int) => FC = a => (_, erased _) => (c, erased d) ?=> a + c
2929

3030
@main def Test() =
3131
assert("a" == useF(ff))

Diff for: tests/run/polymorphic-erased-functions.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import language.experimental.erasedDefinitions
33
object Test extends App {
44

55
// Types
6-
type F1 = [T] => (erased T) => Int
7-
type F2 = [T, U] => (T, erased U) => T
6+
type F1 = [T] => (erased x: T) => Int
7+
type F2 = [T, U] => (t: T, erased u: U) => T
88

99
// Terms
1010
val t1 = [T] => (erased t: T) => 3

0 commit comments

Comments
 (0)