Skip to content

Fix #6009: Emit error when erased is inside the parameter list #6139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
12 changes: 6 additions & 6 deletions docs/docs/reference/other-new-features/erased-terms.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/neg/i6009.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Foo {
def foo(f: (erased Int) => Int): Int = ??? // error: Types with erased keyword can only be function types `erased (...) => ...`
}
6 changes: 6 additions & 0 deletions tests/pos/i6009a.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Foo {
def foo(f: erased Int => Int): Int = {
erased val ctx = 1
f(ctx)
}
}
6 changes: 6 additions & 0 deletions tests/pos/i6009b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Foo {
def foo(f: erased (Int) => Int): Int = {
erased val ctx = 1
f(ctx)
}
}
6 changes: 6 additions & 0 deletions tests/pos/i6009c.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Foo {
def foo(f: given erased Int => Int): Int = {
implicit erased val ctx = 1
f
}
}