Skip to content

Commit 5bbbdce

Browse files
authored
fix: Check if a PolyFunction TypeTree has no ByName parameters (#21671)
2 parents d0d67dc + 60e957c commit 5bbbdce

File tree

6 files changed

+10
-7
lines changed

6 files changed

+10
-7
lines changed

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

Lines changed: 0 additions & 1 deletion
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/reporting/messages.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,12 +1829,11 @@ class NotAPath(tp: Type, usage: String)(using Context) extends TypeMsg(NotAPathI
18291829
if sym.isAllOf(Flags.InlineParam) then
18301830
i"""
18311831
|Inline parameters are not considered immutable paths and cannot be used as
1832-
|singleton types.
1833-
|
1832+
|singleton types.
1833+
|
18341834
|Hint: Removing the `inline` qualifier from the `${sym.name}` parameter
18351835
|may help resolve this issue."""
18361836
else ""
1837-
18381837

18391838
class WrongNumberOfParameters(tree: untpd.Tree, foundCount: Int, pt: Type, expectedCount: Int)(using Context)
18401839
extends SyntaxMsg(WrongNumberOfParametersID) {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1914,7 +1914,6 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
19141914
.showing(i"desugared fun $tree --> $desugared with pt = $pt", typr)
19151915
}
19161916

1917-
19181917
def typedPolyFunction(tree: untpd.PolyFunction, pt: Type)(using Context): Tree =
19191918
val tree1 = desugar.normalizePolyFunction(tree)
19201919
if (ctx.mode is Mode.Type) typed(desugar.makePolyFunctionType(tree1), pt)

tests/neg/21538.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
| ^^^^^^^^^^
44
| (value : V) is not a valid singleton type, since it is not an immutable path
55
| Inline parameters are not considered immutable paths and cannot be used as
6-
| singleton types.
7-
|
6+
| singleton types.
7+
|
88
| Hint: Removing the `inline` qualifier from the `value` parameter
99
| may help resolve this issue.
1010
|

tests/neg/i21652.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Error: tests/neg/i21652.scala:1:8 -----------------------------------------------------------------------------------
2+
1 |def k: [A] => (=> A) => A = // error
3+
| ^^^^^^^^^^^^^^^^^
4+
|Implementation restriction: PolyFunction apply must have exactly one parameter list and optionally type arguments. No by-name nor varags are allowed.

tests/neg/i21652.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def k: [A] => (=> A) => A = // error
2+
[A] => a => a

0 commit comments

Comments
 (0)