Skip to content

Commit 60e957c

Browse files
committed
Let the poly functions validation be handled in Checking
1 parent c83ff66 commit 60e957c

File tree

3 files changed

+5
-22
lines changed

3 files changed

+5
-22
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

-1
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,6 @@ class Definitions {
12211221

12221222
/** Creates a refined `PolyFunction` with an `apply` method with the given info. */
12231223
def apply(mt: MethodOrPoly)(using Context): Type =
1224-
assert(isValidPolyFunctionInfo(mt), s"Not a valid PolyFunction refinement: $mt")
12251224
RefinedType(PolyFunctionClass.typeRef, nme.apply, mt)
12261225

12271226
/** Matches a refined `PolyFunction` type and extracts the apply info.

compiler/src/dotty/tools/dotc/typer/Typer.scala

+2-18
Original file line numberDiff line numberDiff line change
@@ -1914,26 +1914,10 @@ 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
1929-
19301917
def typedPolyFunction(tree: untpd.PolyFunction, pt: Type)(using Context): Tree =
19311918
val tree1 = desugar.normalizePolyFunction(tree)
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)
1919+
if (ctx.mode is Mode.Type) typed(desugar.makePolyFunctionType(tree1), pt)
1920+
else typedPolyFunctionValue(tree1, pt)
19371921

19381922
def typedPolyFunctionValue(tree: untpd.PolyFunction, pt: Type)(using Context): Tree =
19391923
val untpd.PolyFunction(tparams: List[untpd.TypeDef] @unchecked, fun) = tree: @unchecked

tests/neg/i21652.check

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- Error: tests/neg/i21652.scala:1:15 ----------------------------------------------------------------------------------
1+
-- Error: tests/neg/i21652.scala:1:8 -----------------------------------------------------------------------------------
22
1 |def k: [A] => (=> A) => A = // error
3-
| ^^^^
4-
| By-name parameters are not supported in Polymorphic Functions
3+
| ^^^^^^^^^^^^^^^^^
4+
|Implementation restriction: PolyFunction apply must have exactly one parameter list and optionally type arguments. No by-name nor varags are allowed.

0 commit comments

Comments
 (0)