Skip to content

Commit d640193

Browse files
authored
Recognize named arguments in isFunctionWithUnknownParamType (#17161)
fixes #17155
2 parents 3a830c8 + 1d497f5 commit d640193

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

Diff for: compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

+2
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,8 @@ trait UntypedTreeInfo extends TreeInfo[Untyped] { self: Trees.Instance[Untyped]
399399
Some(tree)
400400
case Block(Nil, expr) =>
401401
functionWithUnknownParamType(expr)
402+
case NamedArg(_, expr) =>
403+
functionWithUnknownParamType(expr)
402404
case _ =>
403405
None
404406
}

Diff for: compiler/src/dotty/tools/dotc/typer/Applications.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ trait Applications extends Compatibility {
448448
def rec(t: Type): Type = {
449449
t.widen match{
450450
case funType: MethodType => funType
451-
case funType: PolyType =>
451+
case funType: PolyType =>
452452
rec(instantiateWithTypeVars(funType))
453453
case tp => tp
454454
}

Diff for: tests/pos/i17155.scala

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def foo[A, B](arr: Array[A], pf: PartialFunction[A, B]): Seq[B] = arr.toSeq.collect(pf)
2+
def foo[A, B](list: List[A], pf: PartialFunction[A, B]): Seq[B] = list.collect(pf) // no errors if this is commented out
3+
4+
val arr = Array(1, 2, 3)
5+
val resOkay = foo(arr = arr, { case n if n % 2 != 0 => n.toString }) // compiles
6+
val resNope = foo(arr = arr, pf = { case n if n % 2 != 0 => n.toString }) // Error 1
7+
val resNope2 = foo[Int, String](arr = arr, pf = { case n if n % 2 != 0 => n.toString }) // Error 2

0 commit comments

Comments
 (0)