Skip to content

Commit

Permalink
Simplify erased parameter syntax
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
odersky committed Feb 11, 2024
1 parent 6a9bea8 commit 6159045
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1631,7 +1631,7 @@ object Parsers {
() => funParam(in.offset, imods))
case t =>
def funArg() =
addErased()
erasedArgs.addOne(false)
funArgType()
commaSeparatedRest(t, funArg)
accept(RPAREN)
Expand Down
4 changes: 2 additions & 2 deletions tests/neg/lambda-infer.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//> using options -language:experimental.erasedDefinitions

type F = (Int, erased Int) => Int
type F = (x: Int, erased y: Int) => Int

erased class A

Expand All @@ -14,7 +14,7 @@ erased class A

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

def singleParam(f: (erased Int) => Int) = f(5)
def singleParam(f: (erased x: Int) => Int) = f(5)

singleParam(x => 5) // error: Expected (erased Int) => Int got Int => Int
singleParam((erased x) => 5) // ok
Expand Down
20 changes: 10 additions & 10 deletions tests/neg/polymorphic-erased-functions-types.check
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
| Required: [T] => (x$1: T) => Unit
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: tests/neg/polymorphic-erased-functions-types.scala:4:37 ---------------------------------
4 |def t1b: [T] => (erased T) => Unit = [T] => (t: T) => () // error
| ^^^^^^^^^^^^^^^^^^^
| Found: [T] => (t: T) => Unit
| Required: [T] => (erased x$1: T) => Unit
-- [E007] Type Mismatch Error: tests/neg/polymorphic-erased-functions-types.scala:4:40 ---------------------------------
4 |def t1b: [T] => (erased t: T) => Unit = [T] => (t: T) => () // error
| ^^^^^^^^^^^^^^^^^^^
| Found: [T] => (t: T) => Unit
| Required: [T] => (erased t: T) => Unit
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: tests/neg/polymorphic-erased-functions-types.scala:6:36 ---------------------------------
Expand All @@ -19,10 +19,10 @@
| Required: [T, U] => (x$1: T, x$2: U) => Unit
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: tests/neg/polymorphic-erased-functions-types.scala:7:43 ---------------------------------
7 |def t2b: [T, U] => (T, erased U) => Unit = [T, U] => (t: T, u: U) => () // error
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Found: [T, U] => (t: T, u: U) => Unit
| Required: [T, U] => (x$1: T, erased x$2: U) => Unit
-- [E007] Type Mismatch Error: tests/neg/polymorphic-erased-functions-types.scala:7:49 ---------------------------------
7 |def t2b: [T, U] => (t: T, erased u: U) => Unit = [T, U] => (t: T, u: U) => () // error
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Found: [T, U] => (t: T, u: U) => Unit
| Required: [T, U] => (t: T, erased u: U) => Unit
|
| longer explanation available when compiling with `-explain`
4 changes: 2 additions & 2 deletions tests/neg/polymorphic-erased-functions-types.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import language.experimental.erasedDefinitions

def t1a: [T] => T => Unit = [T] => (erased t: T) => () // error
def t1b: [T] => (erased T) => Unit = [T] => (t: T) => () // error
def t1b: [T] => (erased t: T) => Unit = [T] => (t: T) => () // error

def t2a: [T, U] => (T, U) => Unit = [T, U] => (t: T, erased u: U) => () // error
def t2b: [T, U] => (T, erased U) => Unit = [T, U] => (t: T, u: U) => () // error
def t2b: [T, U] => (t: T, erased u: U) => Unit = [T, U] => (t: T, u: U) => () // error
8 changes: 4 additions & 4 deletions tests/run/erased-lambdas.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

// lambdas should parse and work

type F = (erased Int, String) => String
type S = (Int, erased String) => Int
type F = (erased x: Int, y: String) => String
type S = (x: Int, erased y: String) => Int

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

// contextual lambdas should work

type FC = (Int, erased String) ?=> Int
type FC = (x: Int, erased y: String) ?=> Int

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

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

// nested lambdas should work

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

@main def Test() =
assert("a" == useF(ff))
Expand Down
4 changes: 2 additions & 2 deletions tests/run/polymorphic-erased-functions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import language.experimental.erasedDefinitions
object Test extends App {

// Types
type F1 = [T] => (erased T) => Int
type F2 = [T, U] => (T, erased U) => T
type F1 = [T] => (erased x: T) => Int
type F2 = [T, U] => (t: T, erased u: U) => T

// Terms
val t1 = [T] => (erased t: T) => 3
Expand Down

0 comments on commit 6159045

Please sign in to comment.