Fix AssertionError on incompatible scopes with impl typealias

This has been introduced in 9ecd04f628
This commit is contained in:
Alexander Udalov
2017-08-31 16:14:44 +03:00
parent f695ff96e8
commit 05290c3ed2
5 changed files with 37 additions and 2 deletions
@@ -143,7 +143,9 @@ object HeaderImplDeclarationChecker : DeclarationChecker {
// TODO: replace with 'singleOrNull' as soon as multi-module diagnostic tests are refactored
val singleIncompatibility = compatibility.keys.firstOrNull()
if (singleIncompatibility is Incompatible.ClassScopes) {
assert(descriptor is ClassDescriptor) { "Incompatible.ClassScopes is only possible for a class: $descriptor" }
assert(descriptor is ClassDescriptor || descriptor is TypeAliasDescriptor) {
"Incompatible.ClassScopes is only possible for a class or a typealias: $descriptor"
}
// Do not report "header members are not implemented" for those header members, for which there's a clear
// (albeit maybe incompatible) single implementation suspect, declared in the impl class.
@@ -162,8 +164,11 @@ object HeaderImplDeclarationChecker : DeclarationChecker {
val nonTrivialUnimplemented = singleIncompatibility.unimplemented.filterNot(::hasSingleImplSuspect)
if (nonTrivialUnimplemented.isNotEmpty()) {
val classDescriptor =
(descriptor as? TypeAliasDescriptor)?.expandedType?.constructor?.declarationDescriptor as? ClassDescriptor
?: (descriptor as ClassDescriptor)
diagnosticHolder.report(Errors.HEADER_CLASS_MEMBERS_ARE_NOT_IMPLEMENTED.on(
reportOn, descriptor as ClassDescriptor, nonTrivialUnimplemented
reportOn, classDescriptor, nonTrivialUnimplemented
))
}
}
@@ -0,0 +1,3 @@
package test
header abstract class Writer protected constructor()
@@ -0,0 +1,3 @@
package test
impl typealias Writer = java.io.Writer
@@ -0,0 +1,18 @@
-- Common --
Exit code: OK
Output:
-- JVM --
Exit code: COMPILATION_ERROR
Output:
compiler/testData/multiplatform/regressions/incompatibleClassScopesWithImplTypeAlias/jvm.kt:3:1: error: 'impl' class 'Writer' has no implementation of 'header' class members:
protected constructor Writer()
The following declaration is incompatible because visibility is different:
protected/*protected and package*/ constructor Writer()
The following declaration is incompatible because number of value parameters is different:
protected/*protected and package*/ constructor Writer(p0: Any!)
impl typealias Writer = java.io.Writer
^
@@ -206,6 +206,12 @@ public class MultiPlatformIntegrationTestGenerated extends AbstractMultiPlatform
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/multiplatform/regressions"), Pattern.compile("^([^\\.]+)$"), TargetBackend.ANY, true);
}
@TestMetadata("incompatibleClassScopesWithImplTypeAlias")
public void testIncompatibleClassScopesWithImplTypeAlias() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/multiplatform/regressions/incompatibleClassScopesWithImplTypeAlias/");
doTest(fileName);
}
@TestMetadata("kt17001")
public void testKt17001() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/multiplatform/regressions/kt17001/");