Report warning on hided override by delegation when compile to 1.0 version

This commit is contained in:
Mikhael Bogdanov
2017-01-25 17:27:02 +01:00
parent 09a8a999c8
commit 0006a04b01
7 changed files with 71 additions and 7 deletions
@@ -245,7 +245,7 @@ public interface Errors {
DiagnosticFactory0<KtSuperTypeEntry> SUPERTYPE_NOT_INITIALIZED = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<KtTypeReference> DELEGATION_NOT_TO_INTERFACE = DiagnosticFactory0.create(ERROR);
DiagnosticFactory2<KtDeclaration, CallableMemberDescriptor, List<CallableMemberDescriptor>> DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE = DiagnosticFactory2.create(ERROR);
DiagnosticFactory2<KtDeclaration, CallableMemberDescriptor, List<CallableMemberDescriptor>> DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE = DiagnosticFactory2.create(WARNING);
DiagnosticFactory0<KtTypeReference> SUPERTYPE_NOT_A_CLASS_OR_INTERFACE = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<KtTypeReference> SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<KtTypeReference> SUPERTYPE_IS_SUSPEND_FUNCTION_TYPE = DiagnosticFactory0.create(ERROR);
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.resolve.checkers
import org.jetbrains.kotlin.config.LanguageVersion
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.descriptors.ClassDescriptor
@@ -40,8 +39,6 @@ class DelegationChecker : DeclarationChecker {
bindingContext: BindingContext,
languageVersionSettings: LanguageVersionSettings
) {
if (languageVersionSettings.languageVersion == LanguageVersion.KOTLIN_1_0) return
if (descriptor !is ClassDescriptor) return
if (declaration !is KtClassOrObject) return
@@ -0,0 +1,21 @@
// !LANGUAGE_VERSION: 1.0
public interface Base {
fun getValue(): String
fun test() = getValue()
}
class Delegate : Base {
override fun getValue() = "Delegate"
}
public abstract class MyClass : Base {
override fun test(): String {
return "Class"
}
}
<!DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE!>class A : MyClass(), Base by Delegate() {
override fun getValue() = "Delegate"
}<!>
@@ -0,0 +1,36 @@
package
public final class A : MyClass, Base {
public constructor A()
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*2*/ fun getValue(): kotlin.String
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*2*/ /*delegation*/ fun test(): kotlin.String
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
}
public interface Base {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public abstract fun getValue(): kotlin.String
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open fun test(): kotlin.String
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Delegate : Base {
public constructor Delegate()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ fun getValue(): kotlin.String
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun test(): kotlin.String
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public abstract class MyClass : Base {
public constructor MyClass()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public abstract override /*1*/ /*fake_override*/ fun getValue(): kotlin.String
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ fun test(): kotlin.String
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.MultiTargetPlatform
import org.jetbrains.kotlin.test.InTextDirectivesUtils
import org.jetbrains.kotlin.test.KotlinTestUtils
import org.jetbrains.kotlin.utils.addIfNotNull
import org.junit.Assert
@@ -275,6 +276,7 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
)
val LANGUAGE_DIRECTIVE = "LANGUAGE"
val LANGUAGE_VERSION = "LANGUAGE_VERSION"
private val LANGUAGE_PATTERN = Pattern.compile("([\\+\\-])(\\w+)\\s*")
val API_VERSION_DIRECTIVE = "API_VERSION"
@@ -302,14 +304,17 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
private fun parseLanguageVersionSettings(directiveMap: Map<String, String>): LanguageVersionSettings? {
val apiVersionString = directiveMap[API_VERSION_DIRECTIVE]
val directives = directiveMap[LANGUAGE_DIRECTIVE]
if (apiVersionString == null && directives == null) return null
val languageVersionDirective = directiveMap[LANGUAGE_VERSION]
if (apiVersionString == null && directives == null && languageVersionDirective == null) return null
val apiVersion = (if (apiVersionString != null) ApiVersion.parse(apiVersionString) else ApiVersion.LATEST)
?: error("Unknown API version: $apiVersionString")
val languageFeatures = directives?.let(this::collectLanguageFeatureMap).orEmpty()
return DiagnosticTestLanguageVersionSettings(languageFeatures, apiVersion, LanguageVersion.LATEST)
val languageVersion: LanguageVersion = languageVersionDirective?.let { LanguageVersion.fromVersionString(it) } ?: LanguageVersion.LATEST
return DiagnosticTestLanguageVersionSettings(languageFeatures, apiVersion, languageVersion)
}
private fun collectLanguageFeatureMap(directives: String): Map<LanguageFeature, Boolean> {
@@ -6462,6 +6462,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("simple1.0.kt")
public void testSimple1_0() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/simple1.0.kt");
doTest(fileName);
}
@TestMetadata("simpleNoOverride.kt")
public void testSimpleNoOverride() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegation/memberHidesSupertypeOverride/simpleNoOverride.kt");
-1
View File
@@ -1,6 +1,5 @@
// "Make 'A' abstract" "false"
// ERROR: Class 'X' must override public open fun foo(): Unit defined in X because it inherits many implementations of it
// ERROR: Delegated member 'fun foo(): Unit' hides supertype override: public open fun foo(): Unit defined in E. Please specify proper override explicitly
// ACTION: Create test
// ACTION: Make internal
// ACTION: Make private