Skip to content

Commit f140144

Browse files
committed
Fix inherited default params.
1 parent 68c0c2b commit f140144

File tree

1 file changed

+33
-28
lines changed

1 file changed

+33
-28
lines changed

compiler/src/dotty/tools/backend/sjs/JSExportsGen.scala

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -541,22 +541,8 @@ final class JSExportsGen(jsCodeGen: JSCodeGen)(using Context) {
541541
previousArgsValues: Int => List[js.Tree])(
542542
implicit pos: SourcePosition): js.Tree = {
543543

544-
val targetSym = {
545-
if (sym.isClassConstructor) {
546-
/*/* Get the companion module class.
547-
* For inner classes the sym.owner.companionModule can be broken,
548-
* therefore companionModule is fetched at uncurryPhase.
549-
*/
550-
val companionModule = enteringPhase(currentRun.namerPhase) {
551-
sym.owner.companionModule
552-
}
553-
companionModule.moduleClass*/
554-
sym.owner.companionModule.moduleClass
555-
} else {
556-
sym.owner
557-
}
558-
}
559-
val defaultGetterDenot = targetSym.info.member(DefaultGetterName(sym.name.asTermName, paramIndex))
544+
val targetSym = targetSymForDefaultGetter(sym)
545+
val defaultGetterDenot = this.defaultGetterDenot(targetSym, sym, paramIndex)
560546

561547
assert(defaultGetterDenot.exists, s"need default getter for method ${sym.fullName}")
562548
assert(!defaultGetterDenot.isOverloaded, i"found overloaded default getter $defaultGetterDenot")
@@ -584,6 +570,28 @@ final class JSExportsGen(jsCodeGen: JSCodeGen)(using Context) {
584570
}
585571
}
586572

573+
private def targetSymForDefaultGetter(sym: Symbol): Symbol = {
574+
if (sym.isClassConstructor) {
575+
/*/* Get the companion module class.
576+
* For inner classes the sym.owner.companionModule can be broken,
577+
* therefore companionModule is fetched at uncurryPhase.
578+
*/
579+
val companionModule = enteringPhase(currentRun.namerPhase) {
580+
sym.owner.companionModule
581+
}
582+
companionModule.moduleClass*/
583+
sym.owner.companionModule.moduleClass
584+
} else {
585+
sym.owner
586+
}
587+
}
588+
589+
private def defaultGetterDenot(targetSym: Symbol, sym: Symbol, paramIndex: Int): Denotation =
590+
targetSym.info.member(DefaultGetterName(sym.name.asTermName, paramIndex))
591+
592+
private def defaultGetterDenot(sym: Symbol, paramIndex: Int): Denotation =
593+
defaultGetterDenot(targetSymForDefaultGetter(sym), sym, paramIndex)
594+
587595
/** Generate the final forwarding call to the exported method. */
588596
private def genResult(exported: Exported, args: List[js.Tree], static: Boolean)(
589597
implicit pos: SourcePosition): js.Tree = {
@@ -626,15 +634,12 @@ final class JSExportsGen(jsCodeGen: JSCodeGen)(using Context) {
626634
}
627635

628636
private object ParamSpec {
629-
def forSyntheticParam(sym: Symbol): ParamSpec = {
630-
// Synthetic params are never repeated nor have a default value
631-
new ParamSpec(sym, sym.info, isRepeated = false, hasDefault = false)
632-
}
633-
634-
def apply(sym: Symbol, infoAtElimRepeated: Type, infoAtElimEVT: Type): ParamSpec = {
637+
def apply(methodSym: Symbol, sym: Symbol, infoAtElimRepeated: Type, infoAtElimEVT: Type,
638+
methodHasDefaultParams: Boolean, paramIndex: Int): ParamSpec = {
635639
val isRepeated = infoAtElimRepeated.isRepeatedParam
636640
val info = if (isRepeated) infoAtElimRepeated.repeatedToSingle else infoAtElimEVT
637-
new ParamSpec(sym, info, isRepeated, sym.is(HasDefault))
641+
val hasDefault = methodHasDefaultParams && defaultGetterDenot(methodSym, paramIndex).exists
642+
new ParamSpec(sym, info, isRepeated, hasDefault)
638643
}
639644
}
640645

@@ -651,18 +656,18 @@ final class JSExportsGen(jsCodeGen: JSCodeGen)(using Context) {
651656
val paramNamessNow = sym.info.paramNamess
652657
val paramInfosNow = sym.info.paramInfoss.flatten
653658
val paramSymsAtElimRepeated = atPhase(elimRepeatedPhase)(sym.paramSymss.flatten.filter(_.isTerm))
654-
val (paramNamessAtElimRepeated, paramInfosAtElimRepeated) =
655-
atPhase(elimRepeatedPhase)((sym.info.paramNamess, sym.info.paramInfoss.flatten))
659+
val (paramNamessAtElimRepeated, paramInfosAtElimRepeated, methodHasDefaultParams) =
660+
atPhase(elimRepeatedPhase)((sym.info.paramNamess, sym.info.paramInfoss.flatten, sym.hasDefaultParams))
656661
val (paramNamessAtElimEVT, paramInfosAtElimEVT) =
657662
atPhase(elimErasedValueTypePhase)((sym.info.paramNamess, sym.info.paramInfoss.flatten))
658663

659664
def buildFormalParams(paramSyms: List[Symbol], paramInfosAtElimRepeated: List[Type],
660665
paramInfosAtElimEVT: List[Type]): IndexedSeq[ParamSpec] = {
661666
(for {
662-
(paramSym, infoAtElimRepeated, infoAtElimEVT) <-
663-
paramSyms.lazyZip(paramInfosAtElimRepeated).lazyZip(paramInfosAtElimEVT)
667+
(paramSym, infoAtElimRepeated, infoAtElimEVT, paramIndex) <-
668+
paramSyms.lazyZip(paramInfosAtElimRepeated).lazyZip(paramInfosAtElimEVT).lazyZip(0 until paramSyms.size)
664669
} yield {
665-
ParamSpec(paramSym, infoAtElimRepeated, infoAtElimEVT)
670+
ParamSpec(sym, paramSym, infoAtElimRepeated, infoAtElimEVT, methodHasDefaultParams, paramIndex)
666671
}).toIndexedSeq
667672
}
668673

0 commit comments

Comments
 (0)