diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 43215258f8a3..96d3b538b499 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -908,7 +908,9 @@ object Parsers { case FORSOME => syntaxError(ExistentialTypesNoLongerSupported()); t case _ => if (imods.is(Implicit) && !t.isInstanceOf[FunctionWithMods]) - syntaxError("Types with implicit keyword can only be function types", implicitKwPos(start)) + syntaxError("Types with implicit keyword can only be function types `implicit (...) => ...`", implicitKwPos(start)) + if (imods.is(Erased) && !t.isInstanceOf[FunctionWithMods]) + syntaxError("Types with erased keyword can only be function types `erased (...) => ...`", implicitKwPos(start)) t } } diff --git a/docs/docs/reference/other-new-features/erased-terms.md b/docs/docs/reference/other-new-features/erased-terms.md index b96e212c0c90..c5b0981df487 100644 --- a/docs/docs/reference/other-new-features/erased-terms.md +++ b/docs/docs/reference/other-new-features/erased-terms.md @@ -171,13 +171,13 @@ Rules 3. Functions - * `(erased x1: T1, x2: T2, ..., xN: TN) => y : (erased T1, T2, ..., TN) => R` - * `(implicit erased x1: T1, x2: T2, ..., xN: TN) => y : (implicit erased T1, T2, ..., TN) => R` - * `implicit erased T1 => R <:< erased T1 => R` - * `(implicit erased T1, T2) => R <:< (erased T1, T2) => R` + * `erased (x1: T1, x2: T2, ..., xN: TN) => y : erased (T1, T2, ..., TN) => R` + * `given erased (x1: T1, x2: T2, ..., xN: TN) => y : given erased (T1, T2, ..., TN) => R` + * `given erased T1 => R <:< erased T1 => R` + * `given erased (T1, T2) => R <:< erased (T1, T2) => R` * ... - Note that there is no subtype relation between `erased T => R` and `T => R` (or `implicit erased T => R` and `implicit T => R`) + Note that there is no subtype relation between `erased T => R` and `T => R` (or `given erased T => R` and `given T => R`) 4. Eta expansion @@ -189,7 +189,7 @@ Rules * All `erased` parameters are removed from the function * All argument to `erased` parameters are not passed to the function * All `erased` definitions are removed - * All `(erased T1, T2, ..., TN) => R` and `(implicit erased T1, T2, ..., TN) => R` become `() => R` + * All `(erased T1, T2, ..., TN) => R` and `(given erased T1, T2, ..., TN) => R` become `() => R` 6. Overloading diff --git a/tests/neg/i6009.scala b/tests/neg/i6009.scala new file mode 100644 index 000000000000..1fc07442d96c --- /dev/null +++ b/tests/neg/i6009.scala @@ -0,0 +1,3 @@ +class Foo { + def foo(f: (erased Int) => Int): Int = ??? // error: Types with erased keyword can only be function types `erased (...) => ...` +} diff --git a/tests/pos/i6009a.scala b/tests/pos/i6009a.scala new file mode 100644 index 000000000000..4497ba8a84cf --- /dev/null +++ b/tests/pos/i6009a.scala @@ -0,0 +1,6 @@ +class Foo { + def foo(f: erased Int => Int): Int = { + erased val ctx = 1 + f(ctx) + } +} diff --git a/tests/pos/i6009b.scala b/tests/pos/i6009b.scala new file mode 100644 index 000000000000..e5b4ed0bf744 --- /dev/null +++ b/tests/pos/i6009b.scala @@ -0,0 +1,6 @@ +class Foo { + def foo(f: erased (Int) => Int): Int = { + erased val ctx = 1 + f(ctx) + } +} diff --git a/tests/pos/i6009c.scala b/tests/pos/i6009c.scala new file mode 100644 index 000000000000..e4b1ae559b2b --- /dev/null +++ b/tests/pos/i6009c.scala @@ -0,0 +1,6 @@ +class Foo { + def foo(f: given erased Int => Int): Int = { + implicit erased val ctx = 1 + f + } +}