Skip to content

Commit

Permalink
Convert SAM result types to function types
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed May 31, 2023
1 parent d0b790e commit 8812638
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
9 changes: 9 additions & 0 deletions tests/pos/i17183.scala
Original file line number Diff line number Diff line change
@@ -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 = (_, _) => ???)

0 comments on commit 8812638

Please sign in to comment.