Skip to content

Commit 3bc09f3

Browse files
oderskyWojciechMazur
authored andcommitted
Don't leave underspecified SAM types in the code
Fixes #15785 [Cherry-picked c8f3a6f]
1 parent a9962c1 commit 3bc09f3

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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,8 +1664,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
16641664
// Replace the underspecified expected type by one based on the closure method type
16651665
defn.PartialFunctionOf(mt.firstParamTypes.head, mt.resultType)
16661666
else
1667-
report.error(em"result type of lambda is an underspecified SAM type $samParent", tree.srcPos)
1668-
samParent
1667+
errorType(em"result type of lambda is an underspecified SAM type $samParent", tree.srcPos)
16691668
TypeTree(targetTpe)
16701669
case _ =>
16711670
if (mt.isParamDependent)

tests/neg/i15785.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
trait SAMFunction1[-T1, +R]:
2+
def apply(x1: T1): R
3+
4+
def fooSAM[T](foo: SAMFunction1[T, T] = (f: T) => f): Unit = () // error

0 commit comments

Comments
 (0)