diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 1303b64cbd12..10d8f45b6d01 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1738,8 +1738,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer // Replace the underspecified expected type by one based on the closure method type defn.PartialFunctionOf(mt.firstParamTypes.head, mt.resultType) else - report.error(em"result type of lambda is an underspecified SAM type $samParent", tree.srcPos) - samParent + errorType(em"result type of lambda is an underspecified SAM type $samParent", tree.srcPos) TypeTree(targetTpe) case _ => if (mt.isParamDependent) diff --git a/tests/neg/i15785.scala b/tests/neg/i15785.scala new file mode 100644 index 000000000000..f79da7a16e66 --- /dev/null +++ b/tests/neg/i15785.scala @@ -0,0 +1,4 @@ +trait SAMFunction1[-T1, +R]: + def apply(x1: T1): R + +def fooSAM[T](foo: SAMFunction1[T, T] = (f: T) => f): Unit = () // error