Skip to content

Fix #4725: Expand implicit method to implicit func #4835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/EtaExpansion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions tests/pos/i4725.scala
Original file line number Diff line number Diff line change
@@ -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
}