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

Recognize named arguments in isFunctionWithUnknownParamType #17161

Merged
merged 1 commit into from
Mar 28, 2023
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
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ trait UntypedTreeInfo extends TreeInfo[Untyped] { self: Trees.Instance[Untyped]
Some(tree)
case Block(Nil, expr) =>
functionWithUnknownParamType(expr)
case NamedArg(_, expr) =>
functionWithUnknownParamType(expr)
case _ =>
None
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ trait Applications extends Compatibility {
def rec(t: Type): Type = {
t.widen match{
case funType: MethodType => funType
case funType: PolyType =>
case funType: PolyType =>
rec(instantiateWithTypeVars(funType))
case tp => tp
}
Expand Down
7 changes: 7 additions & 0 deletions tests/pos/i17155.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def foo[A, B](arr: Array[A], pf: PartialFunction[A, B]): Seq[B] = arr.toSeq.collect(pf)
def foo[A, B](list: List[A], pf: PartialFunction[A, B]): Seq[B] = list.collect(pf) // no errors if this is commented out

val arr = Array(1, 2, 3)
val resOkay = foo(arr = arr, { case n if n % 2 != 0 => n.toString }) // compiles
val resNope = foo(arr = arr, pf = { case n if n % 2 != 0 => n.toString }) // Error 1
val resNope2 = foo[Int, String](arr = arr, pf = { case n if n % 2 != 0 => n.toString }) // Error 2