Skip to content

Commit f859640

Browse files
authored
Fix i18518 (#18520)
Fix #18518. It is an implementation restriction that a value parameter has to follow a type abstraction. So `[X] -> T ->{x} U` should be rejected as a capturing type follows the type abstraction,but it wasn't. This PR refines the check in `Parsers.scala` to reject this case properly.
2 parents 8020677 + bb1f028 commit f859640

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,11 @@ object Parsers {
14191419
private def getFunction(tree: Tree): Option[Function] = tree match {
14201420
case Parens(tree1) => getFunction(tree1)
14211421
case Block(Nil, tree1) => getFunction(tree1)
1422+
case Function(_, _: CapturesAndResult) =>
1423+
// A function tree like this will be desugared
1424+
// into a capturing type in the typer,
1425+
// so None is returned.
1426+
None
14221427
case t: Function => Some(t)
14231428
case _ => None
14241429
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import language.experimental.captureChecking
2+
type Foo1 = [R] -> (x: Unit) ->{} Unit // error
3+
type Foo2 = [R] -> (x: Unit) ->{cap} Unit // error
4+
type Foo3 = (c: Int^) -> [R] -> (x: Unit) ->{c} Unit // error
5+
type Foo4 = (c: Int^) -> [R] -> (x0: Unit) -> (x: Unit) ->{c} Unit

0 commit comments

Comments
 (0)