diff --git a/compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala b/compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala index c2f1be2444b7..9ab6664e4857 100644 --- a/compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala +++ b/compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala @@ -208,14 +208,18 @@ object EtaExpansion extends LiftImpure { val paramTypes: List[Tree] = if (isLastApplication && mt.paramInfos.length == xarity) mt.paramInfos map (_ => TypeTree()) else mt.paramInfos map TypeTree + var paramFlag = Synthetic | Param + if (mt.isImplicitMethod) paramFlag |= Implicit val params = (mt.paramNames, paramTypes).zipped.map((name, tpe) => - ValDef(name, tpe, EmptyTree).withFlags(Synthetic | Param).withPos(tree.pos.startPos)) + ValDef(name, tpe, EmptyTree).withFlags(paramFlag).withPos(tree.pos.startPos)) var ids: List[Tree] = mt.paramNames map (name => Ident(name).withPos(tree.pos.startPos)) if (mt.paramInfos.nonEmpty && mt.paramInfos.last.isRepeatedParam) ids = ids.init :+ repeated(ids.last) var body: Tree = Apply(lifted, ids) if (!isLastApplication) body = PostfixOp(body, Ident(nme.WILDCARD)) - val fn = untpd.Function(params, body) + val fn = + if (mt.isImplicitMethod) new untpd.FunctionWithMods(params, body, Modifiers(Implicit)) + else untpd.Function(params, body) if (defs.nonEmpty) untpd.Block(defs.toList map (untpd.TypedSplice(_)), fn) else fn } } diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index da66c5b622b5..3fb6434220a8 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -2336,6 +2336,7 @@ class Typer extends Namer !untpd.isImplicitClosure(tree) && !isApplyProto(pt) && !ctx.mode.is(Mode.Pattern) && + !ctx.mode.is(Mode.ImplicitShadowing) && !ctx.isAfterTyper) { typr.println(i"insert apply on implicit $tree") typed(untpd.Select(untpd.TypedSplice(tree), nme.apply), pt, locked) diff --git a/tests/pos/i4725.scala b/tests/pos/i4725.scala new file mode 100644 index 000000000000..f242915918b0 --- /dev/null +++ b/tests/pos/i4725.scala @@ -0,0 +1,18 @@ +object Test1 { + trait T[A] + + def foo[S[_], A](implicit ev: implicit T[A] => T[S[A]]): Unit = () + implicit def bar[A : T]: T[List[A]] = ??? + + foo[List, Int] +} + +object Test2 { + trait T + trait S + + def foo(implicit ev: implicit T => S): Unit = () + implicit def bar(implicit ev: T): S = ??? + + foo +}