KT-2752: add diagnostic that checks whether Kotlin declarations produce conflicting names in generated JS

This commit is contained in:
Alexey Andreev
2016-05-27 15:33:03 +03:00
parent f70b50b6e2
commit 8f829557c8
26 changed files with 381 additions and 1 deletions
@@ -0,0 +1,7 @@
package foo
class A {
<!JS_NAME_CLASH!>fun bar() = 23<!>
<!JS_NAME_CLASH!>val bar = 23<!>
}
@@ -0,0 +1,13 @@
package
package foo {
public final class A {
public constructor A()
public final val bar: kotlin.Int = 23
public final fun bar(): kotlin.Int
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
}
}
@@ -0,0 +1,11 @@
package foo
class A
class B
val A.foo: Int
get() = 32
val B.foo: Int
get() = 42
@@ -0,0 +1,20 @@
package
package foo {
public val foo.A.foo: kotlin.Int
public val foo.B.foo: kotlin.Int
public final class A {
public constructor A()
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
}
public final class B {
public constructor B()
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
}
}
@@ -0,0 +1,5 @@
package foo
fun bar() = 23
private val bar = 32
@@ -0,0 +1,6 @@
package
package foo {
private val bar: kotlin.Int = 32
public fun bar(): kotlin.Int
}
@@ -0,0 +1,11 @@
// FILE: foo.kt
package foo
fun bar(x: Int) = x
// FILE: foobar.kt
package foo.bar
val x = 42
@@ -0,0 +1,9 @@
package
package foo {
public fun bar(/*0*/ x: kotlin.Int): kotlin.Int
package foo.bar {
public val x: kotlin.Int = 42
}
}
@@ -0,0 +1,11 @@
// FILE: foo.kt
package foo
<!JS_NAME_CLASH!>fun bar() = 23<!>
// FILE: foobar.kt
package foo.bar
val x = 42
@@ -0,0 +1,9 @@
package
package foo {
public fun bar(): kotlin.Int
package foo.bar {
public val x: kotlin.Int = 42
}
}
@@ -0,0 +1,13 @@
// FILE: foo.kt
package foo
private fun bar() = 23
private val bar = 42
// FILE: foobar.kt
package foo.bar
val x = 42
@@ -0,0 +1,10 @@
package
package foo {
private val bar: kotlin.Int = 42
private fun bar(): kotlin.Int
package foo.bar {
public val x: kotlin.Int = 42
}
}
@@ -0,0 +1,11 @@
// FILE: foo.kt
package foo
<!JS_NAME_CLASH!>val bar = 23<!>
// FILE: foobar.kt
package foo.bar
val x = 42
@@ -0,0 +1,9 @@
package
package foo {
public val bar: kotlin.Int = 23
package foo.bar {
public val x: kotlin.Int = 42
}
}
@@ -0,0 +1,9 @@
package foo
open class Super {
<!JS_NAME_CLASH!>val foo = 23<!>
}
class Sub : Super() {
<!JS_NAME_CLASH!>fun foo() = 42<!>
}
@@ -0,0 +1,21 @@
package
package foo {
public final class Sub : foo.Super {
public constructor Sub()
public final override /*1*/ /*fake_override*/ val foo: kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun foo(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public open class Super {
public constructor Super()
public final val foo: kotlin.Int = 23
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
}
}
@@ -0,0 +1,5 @@
package foo
@native fun bar() = 23
val bar = 32
@@ -0,0 +1,6 @@
package
package foo {
public val bar: kotlin.Int = 32
@kotlin.js.native() public fun bar(): kotlin.Int
}
@@ -0,0 +1,5 @@
package foo
<!JS_NAME_CLASH!>fun bar() = 23<!>
<!JS_NAME_CLASH!>val bar = 32<!>
@@ -0,0 +1,6 @@
package
package foo {
public val bar: kotlin.Int = 32
public fun bar(): kotlin.Int
}
@@ -287,6 +287,75 @@ public class DiagnosticsTestWithJsStdLibGenerated extends AbstractDiagnosticsTes
}
}
@TestMetadata("compiler/testData/diagnostics/testsWithJsStdLib/name")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Name extends AbstractDiagnosticsTestWithJsStdLib {
public void testAllFilesPresentInName() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/testsWithJsStdLib/name"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("classLevelMethodAndProperty.kt")
public void testClassLevelMethodAndProperty() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/name/classLevelMethodAndProperty.kt");
doTest(fileName);
}
@TestMetadata("extensionPropertiesWithDifferentReceiversDoNotClash.kt")
public void testExtensionPropertiesWithDifferentReceiversDoNotClash() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/name/extensionPropertiesWithDifferentReceiversDoNotClash.kt");
doTest(fileName);
}
@TestMetadata("methodAndPrivatePropertyDoNotClash.kt")
public void testMethodAndPrivatePropertyDoNotClash() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/name/methodAndPrivatePropertyDoNotClash.kt");
doTest(fileName);
}
@TestMetadata("packageAndMangledMethodDoNotClash.kt")
public void testPackageAndMangledMethodDoNotClash() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/name/packageAndMangledMethodDoNotClash.kt");
doTest(fileName);
}
@TestMetadata("packageAndMethod.kt")
public void testPackageAndMethod() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/name/packageAndMethod.kt");
doTest(fileName);
}
@TestMetadata("packageAndPrivateDeclarationsDoNotClash.kt")
public void testPackageAndPrivateDeclarationsDoNotClash() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/name/packageAndPrivateDeclarationsDoNotClash.kt");
doTest(fileName);
}
@TestMetadata("packageAndProperty.kt")
public void testPackageAndProperty() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/name/packageAndProperty.kt");
doTest(fileName);
}
@TestMetadata("propertyAndMethodInSubclass.kt")
public void testPropertyAndMethodInSubclass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/name/propertyAndMethodInSubclass.kt");
doTest(fileName);
}
@TestMetadata("propertyAndNativeMethodDoNotClash.kt")
public void testPropertyAndNativeMethodDoNotClash() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/name/propertyAndNativeMethodDoNotClash.kt");
doTest(fileName);
}
@TestMetadata("topLevelMethodAndProperty.kt")
public void testTopLevelMethodAndProperty() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/name/topLevelMethodAndProperty.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/diagnostics/testsWithJsStdLib/native")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)