Skip to content

Commit

Permalink
fix: Check if a PolyFunction TypeTree has no ByName parameters (#21671)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbovel authored Oct 3, 2024
2 parents d0d67dc + 60e957c commit 5bbbdce
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 7 deletions.
1 change: 0 additions & 1 deletion compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 2 additions & 3 deletions compiler/src/dotty/tools/dotc/reporting/messages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1829,12 +1829,11 @@ class NotAPath(tp: Type, usage: String)(using Context) extends TypeMsg(NotAPathI
if sym.isAllOf(Flags.InlineParam) then
i"""
|Inline parameters are not considered immutable paths and cannot be used as
|singleton types.
|
|singleton types.
|
|Hint: Removing the `inline` qualifier from the `${sym.name}` parameter
|may help resolve this issue."""
else ""


class WrongNumberOfParameters(tree: untpd.Tree, foundCount: Int, pt: Type, expectedCount: Int)(using Context)
extends SyntaxMsg(WrongNumberOfParametersID) {
Expand Down
1 change: 0 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1914,7 +1914,6 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
.showing(i"desugared fun $tree --> $desugared with pt = $pt", typr)
}


def typedPolyFunction(tree: untpd.PolyFunction, pt: Type)(using Context): Tree =
val tree1 = desugar.normalizePolyFunction(tree)
if (ctx.mode is Mode.Type) typed(desugar.makePolyFunctionType(tree1), pt)
Expand Down
4 changes: 2 additions & 2 deletions tests/neg/21538.check
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
| ^^^^^^^^^^
| (value : V) is not a valid singleton type, since it is not an immutable path
| Inline parameters are not considered immutable paths and cannot be used as
| singleton types.
|
| singleton types.
|
| Hint: Removing the `inline` qualifier from the `value` parameter
| may help resolve this issue.
|
Expand Down
4 changes: 4 additions & 0 deletions tests/neg/i21652.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Error: tests/neg/i21652.scala:1:8 -----------------------------------------------------------------------------------
1 |def k: [A] => (=> A) => A = // error
| ^^^^^^^^^^^^^^^^^
|Implementation restriction: PolyFunction apply must have exactly one parameter list and optionally type arguments. No by-name nor varags are allowed.
2 changes: 2 additions & 0 deletions tests/neg/i21652.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def k: [A] => (=> A) => A = // error
[A] => a => a

0 comments on commit 5bbbdce

Please sign in to comment.