Skip to content

Commit 9e13257

Browse files
authored
Merge pull request #433 from scala/backport-lts-3.3-23246
Backport "Tighten condition when to do SAM type conversion" to 3.3 LTS
2 parents be01462 + fba0da3 commit 9e13257

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1701,7 +1701,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
17011701
case mt: MethodType =>
17021702
pt.findFunctionType match {
17031703
case SAMType(samMeth, samParent)
1704-
if !defn.isFunctionNType(samParent) && mt <:< samMeth =>
1704+
if !ctx.erasedTypes && !defn.isFunctionNType(samParent)
1705+
&& mt <:< samMeth && !mt.isImplicitMethod =>
17051706
if defn.isContextFunctionType(mt.resultType) then
17061707
report.error(
17071708
em"""Implementation restriction: cannot convert this expression to `$samParent`
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
abstract class MyFun:
2+
def apply(x: Int): Int
3+
4+
object Test:
5+
val myFun: MyFun = (x: Int) ?=> x + 10 // error

0 commit comments

Comments
 (0)