Skip to content

Commit ed5e3da

Browse files
committed
fix: better inference for function types when union with Null
1 parent ea1ab6e commit ed5e3da

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1932,7 +1932,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
19321932
case _ =>
19331933
}
19341934

1935-
val (protoFormals, resultTpt) = decomposeProtoFunction(pt, params.length, tree.srcPos)
1935+
val (protoFormals, resultTpt) = decomposeProtoFunction(pt.stripNull(), params.length, tree.srcPos)
19361936

19371937
/** Returns the type and whether the parameter is erased */
19381938
def protoFormal(i: Int): (Type, Boolean) =

tests/pos/i24206.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ class DispatchQuery:
1313
trait Result
1414
def getAll(nameFilter: Option[String => Boolean]): List[Result] = ???
1515
def get(collectionName: String): List[Result] =
16-
getAll(Option(_.startsWith(collectionName)))
16+
getAll(Option(_.startsWith(collectionName)))
17+
18+
def f[T](x: T | Null): T = ???
19+
val _: Any => Any = f(x => x)

0 commit comments

Comments
 (0)