Skip to content

Commit 71008dd

Browse files
jrudolphneko-kai
authored andcommitted
Allow [T] => { (x: T) => x } syntax for polymorphic functions
Fixes #12323
1 parent 1488c64 commit 71008dd

File tree

3 files changed

+5
-0
lines changed

3 files changed

+5
-0
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,6 +1611,8 @@ object desugar {
16111611
def makePolyFunction(targs: List[Tree], body: Tree): Tree = body match {
16121612
case Parens(body1) =>
16131613
makePolyFunction(targs, body1)
1614+
case Block(Nil, body1) =>
1615+
makePolyFunction(targs, body1)
16141616
case Function(vargs, res) =>
16151617
assert(targs.nonEmpty)
16161618
// TODO: Figure out if we need a `PolyFunctionWithMods` instead.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,7 @@ object Parsers {
13121312

13131313
private def isFunction(tree: Tree): Boolean = tree match {
13141314
case Parens(tree1) => isFunction(tree1)
1315+
case Block(Nil, tree1) => isFunction(tree1)
13151316
case _: Function => true
13161317
case _ => false
13171318
}

tests/run/polymorphic-functions.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,6 @@ object Test extends App {
9595
// Parens handling
9696
val tt1: [T] => (T => T) = [T] => (x: T) => x
9797
val tt2: [T] => T => T = [T] => ((x: T) => x)
98+
val tt3: [T] => T => T = [T] => { (x: T) => x }
99+
val tt4: [T] => T => T = [T] => (x: T) => { x }
98100
}

0 commit comments

Comments
 (0)