diff --git a/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala b/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala index a85197671287..f64b970b5c80 100644 --- a/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala +++ b/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala @@ -240,7 +240,6 @@ object ErrorReporting { def err(using Context): Errors = new Errors } - class ImplicitSearchError( arg: tpd.Tree, pt: Type, @@ -249,6 +248,7 @@ class ImplicitSearchError( ignoredInstanceNormalImport: => Option[SearchSuccess], importSuggestionAddendum: => String )(using ctx: Context) { + def missingArgMsg = arg.tpe match { case ambi: AmbiguousImplicits => (ambi.alt1, ambi.alt2) match { diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala index c9c73c758115..4824031f12bc 100644 --- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala +++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala @@ -1050,8 +1050,13 @@ trait Implicits: val generated: Tree = tpd.ref(ref).withSpan(span.startPos) val locked = ctx.typerState.ownedVars val adapted = - if (argument.isEmpty) - adapt(generated, pt.widenExpr, locked) + if argument.isEmpty then + if defn.isContextFunctionType(pt) then + // need to go through typed, to build the context closure + typed(untpd.TypedSplice(generated), pt, locked) + else + // otherwise we can skip typing and go directly to adapt + adapt(generated, pt.widenExpr, locked) else { def untpdGenerated = untpd.TypedSplice(generated) def producesConversion(info: Type): Boolean = info match diff --git a/tests/pos/i14214.scala b/tests/pos/i14214.scala new file mode 100644 index 000000000000..9bf1f8b5ff75 --- /dev/null +++ b/tests/pos/i14214.scala @@ -0,0 +1,16 @@ +class Dummy +given Dummy = ??? +trait Foo +given foo: Foo = ??? +trait Bar +given bar(using Dummy): Bar = ??? + +object Test: + summon[Dummy ?=> Foo] // was error + summon[Dummy ?=> Foo](using foo) // works + summon[Dummy ?=> Foo](using (_: Dummy) ?=> foo) // works + summon[Dummy ?=> Bar] + summon[Dummy ?=> Bar](using bar) // works + summon[Dummy ?=> Bar](using (_: Dummy) ?=> bar) // works + +