Skip to content

[Proof of concept] Polymorphic function types #4672

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 18 commits into from
May 30, 2019
Merged
Changes from 1 commit
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
40 changes: 23 additions & 17 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1418,20 +1418,8 @@ object desugar {
}
}

// begin desugar

// Special case for `Parens` desugaring: unlike all the desugarings below,
// its output is not a new tree but an existing one whose position should
// be preserved, so we shouldn't call `withPos` on it.
tree match {
case Parens(t) =>
return t
case _ =>
}

val desugared = tree match {
case PolyFunction(targs, body) =>
val Function(vargs, res) = body
def makePolyFunction(targs: List[Tree], body: Tree): Tree = body match {
case Function(vargs, res) =>
// TODO: Figure out if we need a `PolyFunctionWithMods` instead.
val mods = body match {
case body: FunctionWithMods => body.mods
Expand All @@ -1455,10 +1443,28 @@ object desugar {

val applyVParams = vargs.asInstanceOf[List[ValDef]]
.map(varg => varg.withAddedFlags(mods.flags | Param))
New(Template(emptyConstructor, List(polyFunctionTpt), Nil, EmptyValDef,
List(DefDef(nme.apply, applyTParams, List(applyVParams), TypeTree(), res))
))
New(Template(emptyConstructor, List(polyFunctionTpt), Nil, EmptyValDef,
List(DefDef(nme.apply, applyTParams, List(applyVParams), TypeTree(), res))
))
}
case _ =>
EmptyTree //may happen for erroneous input
}

// begin desugar

// Special case for `Parens` desugaring: unlike all the desugarings below,
// its output is not a new tree but an existing one whose position should
// be preserved, so we shouldn't call `withPos` on it.
tree match {
case Parens(t) =>
return t
case _ =>
}

val desugared = tree match {
case PolyFunction(targs, body) =>
makePolyFunction(targs, body) orElse tree
case SymbolLit(str) =>
Literal(Constant(scala.Symbol(str)))
case InterpolatedString(id, segments) =>
Expand Down