Skip to content

Commit 8812638

Browse files
committed
Convert SAM result types to function types
1 parent d0b790e commit 8812638

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1335,7 +1335,10 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
13351335
case RefinedType(parent, nme.apply, mt @ MethodTpe(_, formals, restpe))
13361336
if (defn.isNonRefinedFunction(parent) || defn.isErasedFunctionType(parent)) && formals.length == defaultArity =>
13371337
(formals, untpd.DependentTypeTree(syms => restpe.substParams(mt, syms.map(_.termRef))))
1338-
case SAMType(mt @ MethodTpe(_, formals, restpe)) =>
1338+
case pt1 @ SAMType(mt @ MethodTpe(_, formals, methResType)) =>
1339+
val restpe = methResType match
1340+
case mt: MethodType if !mt.isParamDependent => mt.toFunctionType(isJava = pt1.classSymbol.is(JavaDefined))
1341+
case tp => tp
13391342
(formals,
13401343
if (mt.isResultDependent)
13411344
untpd.DependentTypeTree(syms => restpe.substParams(mt, syms.map(_.termRef)))

tests/pos/i17183.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
trait Dependency
2+
3+
trait MyFunc {
4+
def apply(a: Int, b: String)(using Dependency): String
5+
}
6+
7+
case class Context(f: MyFunc)
8+
9+
def test = Context(f = (_, _) => ???)

0 commit comments

Comments
 (0)