From 8812638655ce004d2354716468ebba5b8a18ac14 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Wed, 31 May 2023 18:28:22 +0100 Subject: [PATCH] Convert SAM result types to function types --- compiler/src/dotty/tools/dotc/typer/Typer.scala | 5 ++++- tests/pos/i17183.scala | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i17183.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 2e7444af8e96..375289b5b400 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1335,7 +1335,10 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer case RefinedType(parent, nme.apply, mt @ MethodTpe(_, formals, restpe)) if (defn.isNonRefinedFunction(parent) || defn.isErasedFunctionType(parent)) && formals.length == defaultArity => (formals, untpd.DependentTypeTree(syms => restpe.substParams(mt, syms.map(_.termRef)))) - case SAMType(mt @ MethodTpe(_, formals, restpe)) => + case pt1 @ SAMType(mt @ MethodTpe(_, formals, methResType)) => + val restpe = methResType match + case mt: MethodType if !mt.isParamDependent => mt.toFunctionType(isJava = pt1.classSymbol.is(JavaDefined)) + case tp => tp (formals, if (mt.isResultDependent) untpd.DependentTypeTree(syms => restpe.substParams(mt, syms.map(_.termRef))) diff --git a/tests/pos/i17183.scala b/tests/pos/i17183.scala new file mode 100644 index 000000000000..b53a2b138985 --- /dev/null +++ b/tests/pos/i17183.scala @@ -0,0 +1,9 @@ +trait Dependency + +trait MyFunc { + def apply(a: Int, b: String)(using Dependency): String +} + +case class Context(f: MyFunc) + +def test = Context(f = (_, _) => ???)