diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 40c90bc25e3c..5ba66efae628 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -1419,6 +1419,11 @@ object Parsers { private def getFunction(tree: Tree): Option[Function] = tree match { case Parens(tree1) => getFunction(tree1) case Block(Nil, tree1) => getFunction(tree1) + case Function(_, _: CapturesAndResult) => + // A function tree like this will be desugared + // into a capturing type in the typer, + // so None is returned. + None case t: Function => Some(t) case _ => None } diff --git a/tests/neg-custom-args/captures/i18518.scala b/tests/neg-custom-args/captures/i18518.scala new file mode 100644 index 000000000000..61e63a54141c --- /dev/null +++ b/tests/neg-custom-args/captures/i18518.scala @@ -0,0 +1,5 @@ +import language.experimental.captureChecking +type Foo1 = [R] -> (x: Unit) ->{} Unit // error +type Foo2 = [R] -> (x: Unit) ->{cap} Unit // error +type Foo3 = (c: Int^) -> [R] -> (x: Unit) ->{c} Unit // error +type Foo4 = (c: Int^) -> [R] -> (x0: Unit) -> (x: Unit) ->{c} Unit