Skip to content

Commit 70c43d8

Browse files
Merge pull request #6139 from dotty-staging/fix-#6009
Fix #6009: Emit error when erased is inside the parameter list
2 parents d249926 + 7ae061a commit 70c43d8

File tree

6 files changed

+30
-7
lines changed

6 files changed

+30
-7
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,9 @@ object Parsers {
908908
case FORSOME => syntaxError(ExistentialTypesNoLongerSupported()); t
909909
case _ =>
910910
if (imods.is(Implicit) && !t.isInstanceOf[FunctionWithMods])
911-
syntaxError("Types with implicit keyword can only be function types", implicitKwPos(start))
911+
syntaxError("Types with implicit keyword can only be function types `implicit (...) => ...`", implicitKwPos(start))
912+
if (imods.is(Erased) && !t.isInstanceOf[FunctionWithMods])
913+
syntaxError("Types with erased keyword can only be function types `erased (...) => ...`", implicitKwPos(start))
912914
t
913915
}
914916
}

docs/docs/reference/other-new-features/erased-terms.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,13 @@ Rules
171171

172172

173173
3. Functions
174-
* `(erased x1: T1, x2: T2, ..., xN: TN) => y : (erased T1, T2, ..., TN) => R`
175-
* `(implicit erased x1: T1, x2: T2, ..., xN: TN) => y : (implicit erased T1, T2, ..., TN) => R`
176-
* `implicit erased T1 => R <:< erased T1 => R`
177-
* `(implicit erased T1, T2) => R <:< (erased T1, T2) => R`
174+
* `erased (x1: T1, x2: T2, ..., xN: TN) => y : erased (T1, T2, ..., TN) => R`
175+
* `given erased (x1: T1, x2: T2, ..., xN: TN) => y : given erased (T1, T2, ..., TN) => R`
176+
* `given erased T1 => R <:< erased T1 => R`
177+
* `given erased (T1, T2) => R <:< erased (T1, T2) => R`
178178
* ...
179179

180-
Note that there is no subtype relation between `erased T => R` and `T => R` (or `implicit erased T => R` and `implicit T => R`)
180+
Note that there is no subtype relation between `erased T => R` and `T => R` (or `given erased T => R` and `given T => R`)
181181

182182

183183
4. Eta expansion
@@ -189,7 +189,7 @@ Rules
189189
* All `erased` parameters are removed from the function
190190
* All argument to `erased` parameters are not passed to the function
191191
* All `erased` definitions are removed
192-
* All `(erased T1, T2, ..., TN) => R` and `(implicit erased T1, T2, ..., TN) => R` become `() => R`
192+
* All `(erased T1, T2, ..., TN) => R` and `(given erased T1, T2, ..., TN) => R` become `() => R`
193193

194194

195195
6. Overloading

tests/neg/i6009.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Foo {
2+
def foo(f: (erased Int) => Int): Int = ??? // error: Types with erased keyword can only be function types `erased (...) => ...`
3+
}

tests/pos/i6009a.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Foo {
2+
def foo(f: erased Int => Int): Int = {
3+
erased val ctx = 1
4+
f(ctx)
5+
}
6+
}

tests/pos/i6009b.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Foo {
2+
def foo(f: erased (Int) => Int): Int = {
3+
erased val ctx = 1
4+
f(ctx)
5+
}
6+
}

tests/pos/i6009c.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Foo {
2+
def foo(f: given erased Int => Int): Int = {
3+
implicit erased val ctx = 1
4+
f
5+
}
6+
}

0 commit comments

Comments
 (0)