Skip to content

Commit ea73d0d

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

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
@@ -1922,7 +1922,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
19221922
NoType
19231923
}
19241924

1925-
pt match {
1925+
pt.stripNull() match {
19261926
case pt: TypeVar
19271927
if untpd.isFunctionWithUnknownParamType(tree) && !calleeType.exists =>
19281928
// try to instantiate `pt` if this is possible. If it does not

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)