diff options
author | odersky <odersky@gmail.com> | 2016-12-18 16:05:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-18 16:05:15 +0100 |
commit | 7866bc2620098a7a692b68ac9c37e6d8a05ec774 (patch) | |
tree | fa37e7fe072bfa501666823e2f8c1da7f0f13994 /compiler/src/dotty/tools/dotc/ast/Desugar.scala | |
parent | 18b8daa30916b2efaa59638c21198d401a67e46a (diff) | |
parent | 2e99511840915e2805e7a2c07571d3859a3db698 (diff) | |
download | dotty-7866bc2620098a7a692b68ac9c37e6d8a05ec774.tar.gz dotty-7866bc2620098a7a692b68ac9c37e6d8a05ec774.tar.bz2 dotty-7866bc2620098a7a692b68ac9c37e6d8a05ec774.zip |
Merge pull request #1775 from dotty-staging/add-implicit-funtypes
Add implicit function types
Diffstat (limited to 'compiler/src/dotty/tools/dotc/ast/Desugar.scala')
-rw-r--r-- | compiler/src/dotty/tools/dotc/ast/Desugar.scala | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index bb15edf5a..db78cfffb 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -123,6 +123,13 @@ object desugar { else vdef } + def makeImplicitParameters(tpts: List[Tree], forPrimaryConstructor: Boolean)(implicit ctx: Context) = + for (tpt <- tpts) yield { + val paramFlags: FlagSet = if (forPrimaryConstructor) PrivateLocalParamAccessor else Param + val epname = ctx.freshName(nme.EVIDENCE_PARAM_PREFIX).toTermName + ValDef(epname, tpt, EmptyTree).withFlags(paramFlags | Implicit) + } + /** Expand context bounds to evidence params. E.g., * * def f[T >: L <: H : B](params) @@ -143,19 +150,16 @@ object desugar { val epbuf = new ListBuffer[ValDef] def desugarContextBounds(rhs: Tree): Tree = rhs match { case ContextBounds(tbounds, cxbounds) => - for (cxbound <- cxbounds) { - val paramFlags: FlagSet = if (isPrimaryConstructor) PrivateLocalParamAccessor else Param - val epname = ctx.freshName(nme.EVIDENCE_PARAM_PREFIX).toTermName - epbuf += ValDef(epname, cxbound, EmptyTree).withFlags(paramFlags | Implicit) - } + for (cxbound <- cxbounds) + epbuf ++= makeImplicitParameters(cxbounds, isPrimaryConstructor) tbounds case PolyTypeTree(tparams, body) => cpy.PolyTypeTree(rhs)(tparams, desugarContextBounds(body)) case _ => rhs } - val tparams1 = tparams mapConserve { tdef => - cpy.TypeDef(tdef)(rhs = desugarContextBounds(tdef.rhs)) + val tparams1 = tparams mapConserve { tparam => + cpy.TypeDef(tparam)(rhs = desugarContextBounds(tparam.rhs)) } val meth1 = addEvidenceParams(cpy.DefDef(meth)(tparams = tparams1), epbuf.toList) @@ -680,6 +684,11 @@ object desugar { Function(param :: Nil, Block(vdefs, body)) } + def makeImplicitFunction(formals: List[Type], body: Tree)(implicit ctx: Context): Tree = { + val params = makeImplicitParameters(formals.map(TypeTree), forPrimaryConstructor = false) + new ImplicitFunction(params, body) + } + /** Add annotation with class `cls` to tree: * tree @cls */ |