KT-2752: remove diagnostic that reports about overridden method having several names from different sources. Generate proxies instead. Fix reporting name clash when two distinct fake overrides require same name.
This commit is contained in:
-2
@@ -45,8 +45,6 @@ private val DIAGNOSTIC_FACTORY_TO_RENDERER by lazy {
|
||||
put(ErrorsJs.JS_NAME_ON_ACCESSOR_AND_PROPERTY, "@JsName can be either on a property or its accessors, not both of them")
|
||||
put(ErrorsJs.JS_NAME_IS_NOT_ON_ALL_ACCESSORS, "@JsName should be on all of the property accessors")
|
||||
put(ErrorsJs.JS_NAME_PROHIBITED_FOR_OVERRIDE, "@JsName is prohibited for overridden members")
|
||||
put(ErrorsJs.JS_NAME_OVERRIDE_CLASH, "Conflicting names got from overridden declarations {0} and {1}", Renderers.COMPACT,
|
||||
Renderers.COMPACT)
|
||||
|
||||
this
|
||||
}
|
||||
|
||||
@@ -49,7 +49,6 @@ public interface ErrorsJs {
|
||||
DiagnosticFactory0<KtElement> JS_NAME_ON_ACCESSOR_AND_PROPERTY = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> JS_NAME_IS_NOT_ON_ALL_ACCESSORS = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> JS_NAME_PROHIBITED_FOR_OVERRIDE = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory2<PsiElement, DeclarationDescriptor, DeclarationDescriptor> JS_NAME_OVERRIDE_CLASH = DiagnosticFactory2.create(ERROR);
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
Object _initializer = new Object() {
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
class JsNameClashChecker : SimpleDeclarationChecker {
|
||||
private val fqnGenerator = FQNGenerator()
|
||||
private val scopes = mutableMapOf<DeclarationDescriptor, MutableMap<String, DeclarationDescriptor>>()
|
||||
private val clashedFakeOverrides = mutableMapOf<DeclarationDescriptor, Pair<DeclarationDescriptor, DeclarationDescriptor>>()
|
||||
private val clashedDescriptors = mutableSetOf<DeclarationDescriptor>()
|
||||
|
||||
override fun check(
|
||||
@@ -74,6 +75,14 @@ class JsNameClashChecker : SimpleDeclarationChecker {
|
||||
val existing = scope[name]
|
||||
if (existing != null && existing != overrideFqn.descriptor) {
|
||||
diagnosticHolder.report(ErrorsJs.JS_NAME_CLASH_SYNTHETIC.on(declaration, name, override, existing))
|
||||
break
|
||||
}
|
||||
|
||||
val clashedOverrides = clashedFakeOverrides[override]
|
||||
if (clashedOverrides != null) {
|
||||
val (firstExample, secondExample) = clashedOverrides
|
||||
diagnosticHolder.report(ErrorsJs.JS_NAME_CLASH_SYNTHETIC.on(declaration, name, firstExample, secondExample))
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,6 +120,28 @@ class JsNameClashChecker : SimpleDeclarationChecker {
|
||||
val fqn = fqnGenerator.generate(descriptor)
|
||||
if (fqn.shared && isOpaque(fqn.descriptor)) {
|
||||
target[fqn.names.last()] = fqn.descriptor
|
||||
(fqn.descriptor as? CallableMemberDescriptor)?.let { checkOverrideClashes(it, target) }
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkOverrideClashes(descriptor: CallableMemberDescriptor, target: MutableMap<String, DeclarationDescriptor>) {
|
||||
var overridden = descriptor.overriddenDescriptors
|
||||
while (overridden.isNotEmpty()) {
|
||||
for (overridenDescriptor in overridden) {
|
||||
val overriddenFqn = fqnGenerator.generate(overridenDescriptor)
|
||||
if (overriddenFqn.shared) {
|
||||
val existing = target[overriddenFqn.names.last()]
|
||||
if (existing != null) {
|
||||
if (existing != descriptor && descriptor.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
|
||||
clashedFakeOverrides[descriptor] = Pair(existing, overridenDescriptor)
|
||||
}
|
||||
}
|
||||
else {
|
||||
target[overriddenFqn.names.last()] = descriptor
|
||||
}
|
||||
}
|
||||
}
|
||||
overridden = overridden.flatMap { it.overriddenDescriptors }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.js.resolve.diagnostics
|
||||
|
||||
import org.jetbrains.kotlin.config.LanguageFeatureSettings
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
@@ -31,7 +30,7 @@ class OverriddenJsNameChecker : DeclarationChecker {
|
||||
private val fqnGenerator = FQNGenerator()
|
||||
|
||||
override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, diagnosticHolder: DiagnosticSink,
|
||||
bindingContext: BindingContext, languageFeatureSettings: LanguageFeatureSettings) {
|
||||
bindingContext: BindingContext) {
|
||||
doCheck(descriptor) { first, second ->
|
||||
val psi = descriptor.findPsi() ?: declaration
|
||||
diagnosticHolder.report(ErrorsJs.JS_NAME_OVERRIDE_CLASH.on(psi, first, second))
|
||||
|
||||
Reference in New Issue
Block a user