@@ -456,6 +456,13 @@ class JSCodeGen()(using genCtx: Context) {
456456 i " genNonNativeJSClass() must be called only for non-native JS classes: $sym" )
457457 assert(sym.superClass != NoSymbol , sym)
458458
459+ if (hasDefaultCtorArgsAndJSModule(sym)) {
460+ report.error(
461+ " Implementation restriction: " +
462+ " constructors of non-native JS classes cannot have default parameters if their companion module is JS native." ,
463+ td)
464+ }
465+
459466 val classIdent = encodeClassNameIdent(sym)
460467 val originalName = originalNameOfClass(sym)
461468
@@ -964,42 +971,31 @@ class JSCodeGen()(using genCtx: Context) {
964971 constructorTrees : List [DefDef ]): (Option [List [js.ParamDef ]], js.JSMethodDef ) = {
965972 implicit val pos = classSym.span
966973
967- if (hasDefaultCtorArgsAndJSModule(classSym)) {
968- report.error(
969- " Implementation restriction: " +
970- " constructors of non-native JS classes cannot have default parameters if their companion module is JS native." ,
971- classSym.srcPos)
972- val ctorDef = js.JSMethodDef (js.MemberFlags .empty,
973- js.StringLiteral (" constructor" ), Nil , None , js.Skip ())(
974- OptimizerHints .empty, None )
975- (None , ctorDef)
976- } else {
977- withNewLocalNameScope {
978- localNames.reserveLocalName(JSSuperClassParamName )
979-
980- val ctors : List [js.MethodDef ] = constructorTrees.flatMap { tree =>
981- genMethodWithCurrentLocalNameScope(tree)
982- }
974+ withNewLocalNameScope {
975+ localNames.reserveLocalName(JSSuperClassParamName )
983976
984- val (captureParams, dispatch) =
985- jsExportsGen.genJSConstructorDispatch(constructorTrees.map(_.symbol))
977+ val ctors : List [js.MethodDef ] = constructorTrees.flatMap { tree =>
978+ genMethodWithCurrentLocalNameScope(tree)
979+ }
986980
987- /* Ensure that the first JS class capture is a reference to the JS super class value.
988- * genNonNativeJSClass and genNewAnonJSClass rely on this.
989- */
990- val captureParamsWithJSSuperClass = captureParams.map { params =>
991- val jsSuperClassParam = js.ParamDef (
992- js.LocalIdent (JSSuperClassParamName ), NoOriginalName ,
993- jstpe.AnyType , mutable = false )
994- jsSuperClassParam :: params
995- }
981+ val (captureParams, dispatch) =
982+ jsExportsGen.genJSConstructorDispatch(constructorTrees.map(_.symbol))
996983
997- val ctorDef = JSConstructorGen .buildJSConstructorDef(dispatch, ctors, freshLocalIdent(" overload" )) {
998- msg => report.error(msg, classSym.srcPos)
999- }
984+ /* Ensure that the first JS class capture is a reference to the JS super class value.
985+ * genNonNativeJSClass and genNewAnonJSClass rely on this.
986+ */
987+ val captureParamsWithJSSuperClass = captureParams.map { params =>
988+ val jsSuperClassParam = js.ParamDef (
989+ js.LocalIdent (JSSuperClassParamName ), NoOriginalName ,
990+ jstpe.AnyType , mutable = false )
991+ jsSuperClassParam :: params
992+ }
1000993
1001- (captureParamsWithJSSuperClass, ctorDef)
994+ val ctorDef = JSConstructorGen .buildJSConstructorDef(dispatch, ctors, freshLocalIdent(" overload" )) {
995+ msg => report.error(msg, classSym.srcPos)
1002996 }
997+
998+ (captureParamsWithJSSuperClass, ctorDef)
1003999 }
10041000 }
10051001
0 commit comments