@@ -1914,11 +1914,26 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
19141914 .showing(i " desugared fun $tree --> $desugared with pt = $pt" , typr)
19151915 }
19161916
1917+ /** Check that the PolyFunction doesn't have by-name parameters.
1918+ * Return the unchanged tree if it's valid, or EmptyTree otherwise.
1919+ */
1920+ private def checkPolyTypeTree (tree : untpd.Tree )(using Context ): untpd.Tree =
1921+ val untpd .PolyFunction (tparams : List [untpd.TypeDef ] @ unchecked, fun @ untpd.Function (vparamTypes, res)) = tree : @ unchecked
1922+ var tree1 = tree
1923+ vparamTypes.foreach:
1924+ case t : ByNameTypeTree =>
1925+ report.error(" By-name parameters are not supported in Polymorphic Functions" , t.srcPos)
1926+ tree1 = untpd.EmptyTree
1927+ case _ =>
1928+ tree1
19171929
19181930 def typedPolyFunction (tree : untpd.PolyFunction , pt : Type )(using Context ): Tree =
19191931 val tree1 = desugar.normalizePolyFunction(tree)
1920- if (ctx.mode is Mode .Type ) typed(desugar.makePolyFunctionType(tree1), pt)
1921- else typedPolyFunctionValue(tree1, pt)
1932+ checkPolyTypeTree(tree1) match
1933+ case tree2 : untpd.PolyFunction =>
1934+ if (ctx.mode is Mode .Type ) typed(desugar.makePolyFunctionType(tree2), pt)
1935+ else typedPolyFunctionValue(tree2, pt)
1936+ case untpd.EmptyTree => TypeTree (NoType )
19221937
19231938 def typedPolyFunctionValue (tree : untpd.PolyFunction , pt : Type )(using Context ): Tree =
19241939 val untpd .PolyFunction (tparams : List [untpd.TypeDef ] @ unchecked, fun) = tree : @ unchecked
0 commit comments