Skip to content

Commit cd136e6

Browse files
authored
Merge pull request #4835 from Medowhill/issue4725
Fix #4725: Expand implicit method to implicit func
2 parents 8667793 + cd6758f commit cd136e6

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,18 @@ object EtaExpansion extends LiftImpure {
208208
val paramTypes: List[Tree] =
209209
if (isLastApplication && mt.paramInfos.length == xarity) mt.paramInfos map (_ => TypeTree())
210210
else mt.paramInfos map TypeTree
211+
var paramFlag = Synthetic | Param
212+
if (mt.isImplicitMethod) paramFlag |= Implicit
211213
val params = (mt.paramNames, paramTypes).zipped.map((name, tpe) =>
212-
ValDef(name, tpe, EmptyTree).withFlags(Synthetic | Param).withPos(tree.pos.startPos))
214+
ValDef(name, tpe, EmptyTree).withFlags(paramFlag).withPos(tree.pos.startPos))
213215
var ids: List[Tree] = mt.paramNames map (name => Ident(name).withPos(tree.pos.startPos))
214216
if (mt.paramInfos.nonEmpty && mt.paramInfos.last.isRepeatedParam)
215217
ids = ids.init :+ repeated(ids.last)
216218
var body: Tree = Apply(lifted, ids)
217219
if (!isLastApplication) body = PostfixOp(body, Ident(nme.WILDCARD))
218-
val fn = untpd.Function(params, body)
220+
val fn =
221+
if (mt.isImplicitMethod) new untpd.FunctionWithMods(params, body, Modifiers(Implicit))
222+
else untpd.Function(params, body)
219223
if (defs.nonEmpty) untpd.Block(defs.toList map (untpd.TypedSplice(_)), fn) else fn
220224
}
221225
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2355,6 +2355,7 @@ class Typer extends Namer
23552355
!untpd.isImplicitClosure(tree) &&
23562356
!isApplyProto(pt) &&
23572357
!ctx.mode.is(Mode.Pattern) &&
2358+
!ctx.mode.is(Mode.ImplicitShadowing) &&
23582359
!ctx.isAfterTyper) {
23592360
typr.println(i"insert apply on implicit $tree")
23602361
typed(untpd.Select(untpd.TypedSplice(tree), nme.apply), pt, locked)

tests/pos/i4725.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
object Test1 {
2+
trait T[A]
3+
4+
def foo[S[_], A](implicit ev: implicit T[A] => T[S[A]]): Unit = ()
5+
implicit def bar[A : T]: T[List[A]] = ???
6+
7+
foo[List, Int]
8+
}
9+
10+
object Test2 {
11+
trait T
12+
trait S
13+
14+
def foo(implicit ev: implicit T => S): Unit = ()
15+
implicit def bar(implicit ev: T): S = ???
16+
17+
foo
18+
}

0 commit comments

Comments
 (0)