Skip to content

Commit

Permalink
Recognize named arguments in isFunctionWithUnknownParamType (#17161)
Browse files Browse the repository at this point in the history
fixes #17155
  • Loading branch information
bishabosha authored Mar 28, 2023
2 parents 3a830c8 + 1d497f5 commit d640193
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
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

0 comments on commit d640193

Please sign in to comment.