@@ -456,6 +456,13 @@ class JSCodeGen()(using genCtx: Context) {
456
456
i " genNonNativeJSClass() must be called only for non-native JS classes: $sym" )
457
457
assert(sym.superClass != NoSymbol , sym)
458
458
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
+
459
466
val classIdent = encodeClassNameIdent(sym)
460
467
val originalName = originalNameOfClass(sym)
461
468
@@ -964,42 +971,31 @@ class JSCodeGen()(using genCtx: Context) {
964
971
constructorTrees : List [DefDef ]): (Option [List [js.ParamDef ]], js.JSMethodDef ) = {
965
972
implicit val pos = classSym.span
966
973
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 )
983
976
984
- val (captureParams, dispatch) =
985
- jsExportsGen.genJSConstructorDispatch(constructorTrees.map(_.symbol))
977
+ val ctors : List [js.MethodDef ] = constructorTrees.flatMap { tree =>
978
+ genMethodWithCurrentLocalNameScope(tree)
979
+ }
986
980
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))
996
983
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
+ }
1000
993
1001
- (captureParamsWithJSSuperClass, ctorDef)
994
+ val ctorDef = JSConstructorGen .buildJSConstructorDef(dispatch, ctors, freshLocalIdent(" overload" )) {
995
+ msg => report.error(msg, classSym.srcPos)
1002
996
}
997
+
998
+ (captureParamsWithJSSuperClass, ctorDef)
1003
999
}
1004
1000
}
1005
1001
0 commit comments