Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Check if a PolyFunction TypeTree has no ByName parameters #21671

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading