Skip to content

Commit 659e1f1

Browse files
committed
Use given as necessary in creator expressions
Synthesized creator expressions for classes passed all parameters as normal arguments. This works no longer with `given` clauses. We have use `given` arguments for those.
1 parent ded71bb commit 659e1f1

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,15 @@ object desugar {
500500
case _ =>
501501
constrVparamss
502502
}
503-
New(classTypeRef, vparamss.nestedMap(refOfDef))
503+
val nu = (makeNew(classTypeRef) /: vparamss) { (nu, vparams) =>
504+
val app = Apply(nu, vparams.map(refOfDef))
505+
vparams match {
506+
case vparam :: _ if vparam.mods.is(Given) => app.pushAttachment(ApplyGiven, ())
507+
case _ =>
508+
}
509+
app
510+
}
511+
ensureApplied(nu)
504512
}
505513

506514
val copiedAccessFlags = if (ctx.scala2Setting) EmptyFlags else AccessFlags

compiler/src/dotty/tools/dotc/ast/untpd.scala

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
6868
override def isType: Boolean = body.isType
6969
}
7070

71-
/** A function type with `implicit`, `erased`, or `contextual` modifiers */
71+
/** A function type with `implicit`, `erased`, or `given` modifiers */
7272
class FunctionWithMods(args: List[Tree], body: Tree, val mods: Modifiers)(implicit @constructorOnly src: SourceFile)
7373
extends Function(args, body)
7474

@@ -343,7 +343,13 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
343343
* navigation into these arguments from the IDE, and to do the right thing in
344344
* PrepareInlineable.
345345
*/
346-
def New(tpt: Tree, argss: List[List[Tree]])(implicit ctx: Context): Tree = {
346+
def New(tpt: Tree, argss: List[List[Tree]])(implicit ctx: Context): Tree =
347+
ensureApplied((makeNew(tpt) /: argss)(Apply(_, _)))
348+
349+
/** A new expression with constrictor and possibly type arguments. See
350+
* `New(tpt, argss)` for details.
351+
*/
352+
def makeNew(tpt: Tree)(implicit ctx: Context): Tree = {
347353
val (tycon, targs) = tpt match {
348354
case AppliedTypeTree(tycon, targs) =>
349355
(tycon, targs)
@@ -354,9 +360,8 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
354360
case _ =>
355361
(tpt, Nil)
356362
}
357-
var prefix: Tree = Select(New(tycon), nme.CONSTRUCTOR)
358-
if (targs.nonEmpty) prefix = TypeApply(prefix, targs)
359-
ensureApplied((prefix /: argss)(Apply(_, _)))
363+
val nu: Tree = Select(New(tycon), nme.CONSTRUCTOR)
364+
if (targs.nonEmpty) TypeApply(nu, targs) else nu
360365
}
361366

362367
def Block(stat: Tree, expr: Tree)(implicit src: SourceFile): Block =

0 commit comments

Comments
 (0)