Skip to content

Commit 7445b09

Browse files
committed
Add HasDefault flag to parameters with default arguments
1 parent b41333c commit 7445b09

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,9 @@ object desugar {
269269
}
270270

271271
def normalizedVparamss = meth1.vparamss.map(_.map(vparam =>
272-
cpy.ValDef(vparam)(rhs = EmptyTree)))
272+
if vparam.rhs.isEmpty then vparam
273+
else cpy.ValDef(vparam)(rhs = EmptyTree).withMods(vparam.mods | HasDefault)
274+
))
273275

274276
def defaultGetters(vparamss: List[List[ValDef]], n: Int): List[DefDef] = vparamss match {
275277
case (vparam :: vparams) :: vparamss1 =>
@@ -713,7 +715,10 @@ object desugar {
713715
if (restrictedAccess) mods.withPrivateWithin(constr1.mods.privateWithin)
714716
else mods
715717
}
716-
val app = DefDef(nme.apply, derivedTparams, derivedVparamss, applyResultTpt, widenedCreatorExpr)
718+
val appParamss =
719+
derivedVparamss.nestedZipWithConserve(constrVparamss)((ap, cp) =>
720+
ap.withMods(ap.mods | (cp.mods.flags & HasDefault)))
721+
val app = DefDef(nme.apply, derivedTparams, appParamss, applyResultTpt, widenedCreatorExpr)
717722
.withMods(appMods)
718723
app :: widenDefs
719724
}

compiler/src/dotty/tools/dotc/core/Flags.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,8 @@ object Flags {
299299
val (SuperParamAliasOrScala2x @ _, SuperParamAlias @ _, Scala2x @ _) = newFlags(26, "<super-param-alias>", "<scala-2.x>")
300300

301301
/** A method that has default params */
302-
val (_, DefaultParameterized @ _, _) = newFlags(27, "<defaultparam>")
302+
val (_, HasDefault @ _, _) = newFlags(27, "<defaultparam>")
303+
val DefaultParameterized = HasDefault // for now
303304

304305
/** An extension method, or a collective extension instance */
305306
val (_, Extension @ _, _) = newFlags(28, "<extension>")

0 commit comments

Comments
 (0)