[JS FIR] Add JS_NAME_CLASH tests for constructors
^KT-64867 Related
This commit is contained in:
committed by
Space Team
parent
5da4d31d37
commit
3dd4a0d868
+49
@@ -0,0 +1,49 @@
|
||||
// FIR_DIFFERENCE
|
||||
// K1 doesn't detect a clash between constructors in one class.
|
||||
// It doesn't seem correct (KT-64976) because it leads to a clash in the generated JS code. K2 works correctly.
|
||||
// !DIAGNOSTICS: -OPT_IN_USAGE
|
||||
|
||||
@JsExport
|
||||
class ClassA {
|
||||
val x: String
|
||||
|
||||
@JsName("constructorA")
|
||||
constructor(y: String) {
|
||||
x = "fromString:$y"
|
||||
}
|
||||
|
||||
@JsName("constructorOther")
|
||||
constructor(y: Int) {
|
||||
x = "fromInt:$y"
|
||||
}
|
||||
}
|
||||
|
||||
@JsExport
|
||||
class ClassB {
|
||||
val x: String
|
||||
|
||||
@JsName("constructorB")
|
||||
constructor(y: String) {
|
||||
x = "fromString:$y"
|
||||
}
|
||||
|
||||
@JsName("constructorOther")
|
||||
constructor(y: Int) {
|
||||
x = "fromInt:$y"
|
||||
}
|
||||
}
|
||||
|
||||
@JsExport
|
||||
class ClassC {
|
||||
val x: String
|
||||
|
||||
@JsName("constructorC")
|
||||
<!JS_NAME_CLASH!>constructor(y: String)<!> {
|
||||
x = "fromString:$y"
|
||||
}
|
||||
|
||||
@JsName("constructorC")
|
||||
<!JS_NAME_CLASH!>constructor(y: Int)<!> {
|
||||
x = "fromInt:$y"
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
// FIR_DIFFERENCE
|
||||
// K1 doesn't detect a clash between constructors in one class.
|
||||
// It doesn't seem correct (KT-64976) because it leads to a clash in the generated JS code. K2 works correctly.
|
||||
// !DIAGNOSTICS: -OPT_IN_USAGE
|
||||
|
||||
@JsExport
|
||||
class ClassA {
|
||||
val x: String
|
||||
|
||||
@JsName("constructorA")
|
||||
constructor(y: String) {
|
||||
x = "fromString:$y"
|
||||
}
|
||||
|
||||
@JsName("constructorOther")
|
||||
constructor(y: Int) {
|
||||
x = "fromInt:$y"
|
||||
}
|
||||
}
|
||||
|
||||
@JsExport
|
||||
class ClassB {
|
||||
val x: String
|
||||
|
||||
@JsName("constructorB")
|
||||
constructor(y: String) {
|
||||
x = "fromString:$y"
|
||||
}
|
||||
|
||||
@JsName("constructorOther")
|
||||
constructor(y: Int) {
|
||||
x = "fromInt:$y"
|
||||
}
|
||||
}
|
||||
|
||||
@JsExport
|
||||
class ClassC {
|
||||
val x: String
|
||||
|
||||
@JsName("constructorC")
|
||||
constructor(y: String) {
|
||||
x = "fromString:$y"
|
||||
}
|
||||
|
||||
@JsName("constructorC")
|
||||
constructor(y: Int) {
|
||||
x = "fromInt:$y"
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package
|
||||
|
||||
@kotlin.js.JsExport public final class ClassA {
|
||||
@kotlin.js.JsName(name = "constructorOther") public constructor ClassA(/*0*/ y: kotlin.Int)
|
||||
@kotlin.js.JsName(name = "constructorA") public constructor ClassA(/*0*/ y: kotlin.String)
|
||||
public final val x: kotlin.String
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
@kotlin.js.JsExport public final class ClassB {
|
||||
@kotlin.js.JsName(name = "constructorOther") public constructor ClassB(/*0*/ y: kotlin.Int)
|
||||
@kotlin.js.JsName(name = "constructorB") public constructor ClassB(/*0*/ y: kotlin.String)
|
||||
public final val x: kotlin.String
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
@kotlin.js.JsExport public final class ClassC {
|
||||
@kotlin.js.JsName(name = "constructorC") public constructor ClassC(/*0*/ y: kotlin.Int)
|
||||
@kotlin.js.JsName(name = "constructorC") public constructor ClassC(/*0*/ y: kotlin.String)
|
||||
public final val x: kotlin.String
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
+6
@@ -3250,6 +3250,12 @@ public class FirJsES6BoxTestGenerated extends AbstractFirJsES6BoxTest {
|
||||
runTest("js/js.translator/testData/box/export/reservedModuleNameInExportedFile.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("topLevelAndClassCtrNameClash.kt")
|
||||
public void testTopLevelAndClassCtrNameClash() throws Exception {
|
||||
runTest("js/js.translator/testData/box/export/topLevelAndClassCtrNameClash.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("vararg.kt")
|
||||
public void testVararg() throws Exception {
|
||||
|
||||
Generated
+6
@@ -3144,6 +3144,12 @@ public class FirLightTreeJsBoxTestGenerated extends AbstractFirLightTreeJsBoxTes
|
||||
runTest("js/js.translator/testData/box/export/reservedModuleNameInExportedFile.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("topLevelAndClassCtrNameClash.kt")
|
||||
public void testTopLevelAndClassCtrNameClash() throws Exception {
|
||||
runTest("js/js.translator/testData/box/export/topLevelAndClassCtrNameClash.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("vararg.kt")
|
||||
public void testVararg() throws Exception {
|
||||
|
||||
+6
@@ -700,6 +700,12 @@ public class FirLightTreeJsOldFrontendDiagnosticsTestGenerated extends AbstractF
|
||||
runTest("compiler/testData/diagnostics/testsWithJsStdLib/name/conflictingNamesFromSuperclass.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("constructorsWithSameJsName.kt")
|
||||
public void testConstructorsWithSameJsName() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithJsStdLib/name/constructorsWithSameJsName.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("declarationClash.kt")
|
||||
public void testDeclarationClash() throws Exception {
|
||||
|
||||
+6
@@ -3144,6 +3144,12 @@ public class FirPsiJsBoxTestGenerated extends AbstractFirPsiJsBoxTest {
|
||||
runTest("js/js.translator/testData/box/export/reservedModuleNameInExportedFile.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("topLevelAndClassCtrNameClash.kt")
|
||||
public void testTopLevelAndClassCtrNameClash() throws Exception {
|
||||
runTest("js/js.translator/testData/box/export/topLevelAndClassCtrNameClash.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("vararg.kt")
|
||||
public void testVararg() throws Exception {
|
||||
|
||||
+6
@@ -700,6 +700,12 @@ public class FirPsiJsOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiJ
|
||||
runTest("compiler/testData/diagnostics/testsWithJsStdLib/name/conflictingNamesFromSuperclass.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("constructorsWithSameJsName.kt")
|
||||
public void testConstructorsWithSameJsName() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithJsStdLib/name/constructorsWithSameJsName.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("declarationClash.kt")
|
||||
public void testDeclarationClash() throws Exception {
|
||||
|
||||
Generated
+6
@@ -700,6 +700,12 @@ public class DiagnosticsWithJsStdLibTestGenerated extends AbstractDiagnosticsTes
|
||||
runTest("compiler/testData/diagnostics/testsWithJsStdLib/name/conflictingNamesFromSuperclass.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("constructorsWithSameJsName.kt")
|
||||
public void testConstructorsWithSameJsName() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithJsStdLib/name/constructorsWithSameJsName.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("declarationClash.kt")
|
||||
public void testDeclarationClash() throws Exception {
|
||||
|
||||
+6
@@ -3250,6 +3250,12 @@ public class IrBoxJsES6TestGenerated extends AbstractIrBoxJsES6Test {
|
||||
runTest("js/js.translator/testData/box/export/reservedModuleNameInExportedFile.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("topLevelAndClassCtrNameClash.kt")
|
||||
public void testTopLevelAndClassCtrNameClash() throws Exception {
|
||||
runTest("js/js.translator/testData/box/export/topLevelAndClassCtrNameClash.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("vararg.kt")
|
||||
public void testVararg() throws Exception {
|
||||
|
||||
+6
@@ -3144,6 +3144,12 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
|
||||
runTest("js/js.translator/testData/box/export/reservedModuleNameInExportedFile.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("topLevelAndClassCtrNameClash.kt")
|
||||
public void testTopLevelAndClassCtrNameClash() throws Exception {
|
||||
runTest("js/js.translator/testData/box/export/topLevelAndClassCtrNameClash.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("vararg.kt")
|
||||
public void testVararg() throws Exception {
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
// IGNORE_BACKEND_K1: JS_IR, JS_IR_ES6
|
||||
// K1 reports a name clash error between top-level declarations and constructors. It seems relevant for legacy JS BE;
|
||||
// however, this is not applicable to JS IR BE because in the generated JS code, there is no name clash.
|
||||
// K2 doesn't report anything and works correctly with JS IR BE.
|
||||
|
||||
// RUN_PLAIN_BOX_FUNCTION
|
||||
// MODULE: lib
|
||||
// FILE: lib.kt
|
||||
@JsExport
|
||||
class ClassA {
|
||||
val a: String
|
||||
|
||||
@JsName("createFromString")
|
||||
constructor(y: String) {
|
||||
a = "ClassA:fromString:$y"
|
||||
}
|
||||
|
||||
@JsName("createFromInt")
|
||||
constructor(y: Int) {
|
||||
a = "ClassA:fromInt:$y"
|
||||
}
|
||||
}
|
||||
|
||||
@JsExport
|
||||
class ClassB {
|
||||
val b: String
|
||||
|
||||
@JsName("createFromString")
|
||||
constructor(y: String) {
|
||||
b = "ClassB:fromString:$y"
|
||||
}
|
||||
|
||||
@JsName("createFromInt")
|
||||
constructor(y: Int) {
|
||||
b = "ClassB:fromInt:$y"
|
||||
}
|
||||
}
|
||||
|
||||
@JsExport
|
||||
fun createFromString(y: String) = "fromString:$y";
|
||||
|
||||
@JsExport
|
||||
fun createFromInt(y: Int) = "fromInt:$y";
|
||||
|
||||
// FILE: main.js
|
||||
function box() {
|
||||
var a1 = this.lib.ClassA.createFromString("A1");
|
||||
var a2 = this.lib.ClassA.createFromInt(2);
|
||||
var b3 = this.lib.ClassB.createFromString("B3");
|
||||
var b4 = this.lib.ClassB.createFromInt(4);
|
||||
var x5 = this.lib.createFromString("X5");
|
||||
var x6 = this.lib.createFromInt(6);
|
||||
|
||||
if (a1.a !== "ClassA:fromString:A1") return "Error: '" + a1.a + "' !== 'ClassA:fromString:A1'"
|
||||
if (a2.a !== "ClassA:fromInt:2") return "Error: '" + a2.a + "' !== 'ClassA:fromInt:2'"
|
||||
if (b3.b !== "ClassB:fromString:B3") return "Error: '" + b3.b + "' !== 'ClassB:fromString:B3'"
|
||||
if (b4.b !== "ClassB:fromInt:4") return "Error: '" + b4.b + "' !== 'ClassB:fromInt:4'"
|
||||
if (x5 !== "fromString:X5") return "Error: '" + x5 + "' !== 'fromString:X5'"
|
||||
if (x6 !== "fromInt:6") return "Error: '" + x6 + "' !== 'fromInt:6'"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user