Skip to content

Commit

Permalink
Don't leave underspecified SAM types in the code
Browse files Browse the repository at this point in the history
Fixes #15785

[Cherry-picked c8f3a6f]
  • Loading branch information
odersky authored and WojciechMazur committed Jun 27, 2024
1 parent a9962c1 commit 3bc09f3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 1 addition & 2 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions tests/neg/i15785.scala
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3bc09f3

Please sign in to comment.