KT-2752: fix name clash diagnostic for case of extension property. Add more tests for the diagnostic
This commit is contained in:
+8
@@ -0,0 +1,8 @@
|
||||
package foo
|
||||
|
||||
class A
|
||||
|
||||
<!JS_NAME_CLASH!>fun A.get_bar() = 23<!>
|
||||
|
||||
val A.bar: Int
|
||||
<!JS_NAME_CLASH!>get() = 42<!>
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package
|
||||
|
||||
package foo {
|
||||
public val foo.A.bar: kotlin.Int
|
||||
public fun foo.A.get_bar(): 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
|
||||
}
|
||||
}
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
package foo
|
||||
|
||||
class A
|
||||
|
||||
fun A.bar() = 32
|
||||
|
||||
val A.bar: Int
|
||||
get() = 32
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
package
|
||||
|
||||
package foo {
|
||||
public val foo.A.bar: kotlin.Int
|
||||
public fun foo.A.bar(): 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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package foo
|
||||
|
||||
<!JS_NAME_CLASH!>fun bar(x: Int) = x<!>
|
||||
|
||||
<!JS_NAME_CLASH!>fun `bar_za3lpa$`() = 42<!>
|
||||
@@ -0,0 +1,6 @@
|
||||
package
|
||||
|
||||
package foo {
|
||||
public fun bar(/*0*/ x: kotlin.Int): kotlin.Int
|
||||
public fun `bar_za3lpa$`(): kotlin.Int
|
||||
}
|
||||
+18
@@ -307,6 +307,24 @@ public class DiagnosticsTestWithJsStdLibGenerated extends AbstractDiagnosticsTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("extensionPropertyAndMethod.kt")
|
||||
public void testExtensionPropertyAndMethod() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/name/extensionPropertyAndMethod.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("extensionPropertyAndMethodDoNotClash.kt")
|
||||
public void testExtensionPropertyAndMethodDoNotClash() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/name/extensionPropertyAndMethodDoNotClash.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("methodAndMethod.kt")
|
||||
public void testMethodAndMethod() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/name/methodAndMethod.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("methodAndPrivatePropertyDoNotClash.kt")
|
||||
public void testMethodAndPrivatePropertyDoNotClash() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/name/methodAndPrivatePropertyDoNotClash.kt");
|
||||
|
||||
@@ -61,7 +61,12 @@ class FQNGenerator {
|
||||
}
|
||||
|
||||
val (localName, shared, parent) = getLocalName(descriptor)
|
||||
return FQNPart(listOf(localName), shared, descriptor, parent)
|
||||
return FQNPart(listOf(localName), shared, descriptor, fixParent(parent))
|
||||
}
|
||||
|
||||
private fun fixParent(parent: DeclarationDescriptor) = when (parent) {
|
||||
is PropertyDescriptor -> parent.containingDeclaration
|
||||
else -> parent
|
||||
}
|
||||
|
||||
private fun getLocalName(descriptor: DeclarationDescriptor): LocalName {
|
||||
|
||||
@@ -22,9 +22,11 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
||||
import org.jetbrains.kotlin.js.naming.FQNGenerator
|
||||
import org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtProperty
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DeclarationChecker
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.resolve.source.getPsi
|
||||
|
||||
@@ -39,7 +41,9 @@ class JsNameChecker : DeclarationChecker {
|
||||
diagnosticHolder: DiagnosticSink,
|
||||
bindingContext: BindingContext
|
||||
) {
|
||||
checkDescriptor(descriptor, declaration, diagnosticHolder)
|
||||
if (declaration !is KtProperty || !descriptor.isExtension) {
|
||||
checkDescriptor(descriptor, declaration, diagnosticHolder)
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkDescriptor(descriptor: DeclarationDescriptor, declaration: KtDeclaration, diagnosticHolder: DiagnosticSink) {
|
||||
@@ -87,6 +91,15 @@ class JsNameChecker : DeclarationChecker {
|
||||
|
||||
private fun collect(scope: MemberScope, target: MutableMap<String, DeclarationDescriptor>) {
|
||||
for (descriptor in scope.getContributedDescriptors()) {
|
||||
collect(descriptor, target)
|
||||
}
|
||||
}
|
||||
|
||||
private fun collect(descriptor: DeclarationDescriptor, target: MutableMap<String, DeclarationDescriptor>) {
|
||||
if (descriptor is PropertyDescriptor && descriptor.isExtension) {
|
||||
descriptor.accessors.forEach { collect(it, target) }
|
||||
}
|
||||
else {
|
||||
val fqn = fqnGenerator.generate(descriptor)
|
||||
if (fqn.shared && isOpaque(fqn.descriptor)) {
|
||||
target[fqn.names.last()] = fqn.descriptor
|
||||
@@ -94,13 +107,6 @@ class JsNameChecker : DeclarationChecker {
|
||||
}
|
||||
}
|
||||
|
||||
private fun collect(descriptor: DeclarationDescriptor, target: MutableMap<String, DeclarationDescriptor>) {
|
||||
val fqn = fqnGenerator.generate(descriptor)
|
||||
if (fqn.shared && isOpaque(fqn.descriptor)) {
|
||||
target[fqn.names.last()] = fqn.descriptor
|
||||
}
|
||||
}
|
||||
|
||||
private fun isOpaque(descriptor: DeclarationDescriptor) =
|
||||
!AnnotationsUtils.isNativeObject(descriptor) && !AnnotationsUtils.isLibraryObject(descriptor)
|
||||
}
|
||||
Reference in New Issue
Block a user