From 60e957c50ddcbf6c64377af1e413237d2063190d Mon Sep 17 00:00:00 2001 From: Kacper Korban Date: Thu, 3 Oct 2024 10:47:45 +0200 Subject: [PATCH] Let the poly functions validation be handled in Checking --- .../dotty/tools/dotc/core/Definitions.scala | 1 - .../src/dotty/tools/dotc/typer/Typer.scala | 20 ++----------------- tests/neg/i21652.check | 6 +++--- 3 files changed, 5 insertions(+), 22 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index f95bb3cea351..0195a4ddbf34 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -1221,7 +1221,6 @@ class Definitions { /** Creates a refined `PolyFunction` with an `apply` method with the given info. */ def apply(mt: MethodOrPoly)(using Context): Type = - assert(isValidPolyFunctionInfo(mt), s"Not a valid PolyFunction refinement: $mt") RefinedType(PolyFunctionClass.typeRef, nme.apply, mt) /** Matches a refined `PolyFunction` type and extracts the apply info. diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 2900a702a5d5..3ed34532aa8f 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1914,26 +1914,10 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer .showing(i"desugared fun $tree --> $desugared with pt = $pt", typr) } - /** Check that the PolyFunction doesn't have by-name parameters. - * Return the unchanged tree if it's valid, or EmptyTree otherwise. - */ - private def checkPolyTypeTree(tree: untpd.Tree)(using Context): untpd.Tree = - val untpd.PolyFunction(tparams: List[untpd.TypeDef] @unchecked, fun @ untpd.Function(vparamTypes, res)) = tree: @unchecked - var tree1 = tree - vparamTypes.foreach: - case t: ByNameTypeTree => - report.error("By-name parameters are not supported in Polymorphic Functions", t.srcPos) - tree1 = untpd.EmptyTree - case _ => - tree1 - def typedPolyFunction(tree: untpd.PolyFunction, pt: Type)(using Context): Tree = val tree1 = desugar.normalizePolyFunction(tree) - checkPolyTypeTree(tree1) match - case tree2: untpd.PolyFunction => - if (ctx.mode is Mode.Type) typed(desugar.makePolyFunctionType(tree2), pt) - else typedPolyFunctionValue(tree2, pt) - case untpd.EmptyTree => TypeTree(NoType) + if (ctx.mode is Mode.Type) typed(desugar.makePolyFunctionType(tree1), pt) + else typedPolyFunctionValue(tree1, pt) def typedPolyFunctionValue(tree: untpd.PolyFunction, pt: Type)(using Context): Tree = val untpd.PolyFunction(tparams: List[untpd.TypeDef] @unchecked, fun) = tree: @unchecked diff --git a/tests/neg/i21652.check b/tests/neg/i21652.check index 14ca8e2dc9db..6cc024e1bb55 100644 --- a/tests/neg/i21652.check +++ b/tests/neg/i21652.check @@ -1,4 +1,4 @@ --- Error: tests/neg/i21652.scala:1:15 ---------------------------------------------------------------------------------- +-- Error: tests/neg/i21652.scala:1:8 ----------------------------------------------------------------------------------- 1 |def k: [A] => (=> A) => A = // error - | ^^^^ - | By-name parameters are not supported in Polymorphic Functions + | ^^^^^^^^^^^^^^^^^ + |Implementation restriction: PolyFunction apply must have exactly one parameter list and optionally type arguments. No by-name nor varags are allowed.