Skip to content

Commit e0c81a5

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 6d2277a commit e0c81a5

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,16 @@ 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)
512+
//.reporting(res => i"CREATE $cdef = $res")
504513
}
505514

506515
val copiedAccessFlags = if (ctx.scala2Setting) EmptyFlags else AccessFlags
@@ -847,7 +856,7 @@ object desugar {
847856
*/
848857
def normalizeName(mdef: MemberDef, impl: Tree)(implicit ctx: Context): Name = {
849858
var name = mdef.name
850-
if (name.isEmpty) name = name.likeSpaced(s"${inventName(impl)}_instance".toTermName)
859+
if (name.isEmpty) name = name.likeSpaced(s"${inventName(impl)}_ev".toTermName)
851860
if (ctx.owner == defn.ScalaPackageClass && defn.reservedScalaClassNames.contains(name.toTypeName)) {
852861
def kind = if (name.isTypeName) "class" else "object"
853862
ctx.error(em"illegal redefinition of standard $kind $name", mdef.sourcePos)

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)