From 3bc09f3c4e020c096dd2571af2142d622b9ee042 Mon Sep 17 00:00:00 2001 From: odersky Date: Tue, 16 Jan 2024 18:08:23 +0100 Subject: [PATCH] Don't leave underspecified SAM types in the code Fixes #15785 [Cherry-picked c8f3a6f5b58a909a711eaf1ab8b0ae2caa47886b] --- compiler/src/dotty/tools/dotc/typer/Typer.scala | 3 +-- tests/neg/i15785.scala | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 tests/neg/i15785.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 8c7add6eba37..7318c4b47e1f 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1664,8 +1664,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