Improve diagnostics on header/impl classes when scopes don't match

Try to report most of the errors on the actual members of the impl
class. In many cases, there's a 1:1 mapping of header to impl class
members, so the error "some members are not implemented" on the class
declaration itself is redundant. Exceptions include functions/properties
from supertypes (there may be no other place to report a signature
mismatch error in this case), functions/properties not marked with
'impl' (the checker is only run for declarations explicitly marked with
'impl') and default constructors (the checker is not run for them)

 #KT-18447 Fixed
This commit is contained in:
Alexander Udalov
2017-07-18 17:28:33 +03:00
parent 74ba0080b1
commit 9ecd04f628
17 changed files with 207 additions and 89 deletions
@@ -5,18 +5,9 @@ Output:
-- JVM --
Exit code: COMPILATION_ERROR
Output:
compiler/testData/multiplatform/classScopes/constructorIncorrectSignature/jvm.kt:1:12: error: 'impl' class 'Foo' has no corresponding 'header' declaration
The following declaration is incompatible because some members are not implemented:
public final header class Foo
No implementations are found for members listed below:
compiler/testData/multiplatform/classScopes/constructorIncorrectSignature/jvm.kt:2:10: error: 'impl' constructor of 'Foo' has no corresponding 'header' declaration
The following declaration is incompatible because parameter types are different:
public constructor Foo(s: String)
The following declaration is incompatible because parameter types are different:
public constructor Foo(s: Array<String>)
impl class Foo {
^
compiler/testData/multiplatform/classScopes/constructorIncorrectSignature/jvm.kt:2:10: error: 'impl' constructor of 'Foo' has no corresponding 'header' declaration
impl constructor(s: Array<String>)
^
@@ -5,18 +5,9 @@ Output:
-- JVM --
Exit code: COMPILATION_ERROR
Output:
compiler/testData/multiplatform/classScopes/functionIncorrectSignature/jvm.kt:1:12: error: 'impl' class 'Foo' has no corresponding 'header' declaration
The following declaration is incompatible because some members are not implemented:
public final header class Foo
No implementations are found for members listed below:
compiler/testData/multiplatform/classScopes/functionIncorrectSignature/jvm.kt:2:5: error: 'impl' function 'function' has no corresponding 'header' declaration
The following declaration is incompatible because return type is different:
public final header fun function(b: ByteArray): Int
The following declaration is incompatible because return type is different:
public final impl fun function(b: ByteArray): Long
impl class Foo {
^
compiler/testData/multiplatform/classScopes/functionIncorrectSignature/jvm.kt:2:5: error: 'impl' function 'function' has no corresponding 'header' declaration
impl fun function(b: ByteArray): Long = b.size.toLong()
^
@@ -0,0 +1,3 @@
header class Foo {
fun function(b: ByteArray): Int
}
@@ -0,0 +1,5 @@
open class Base {
fun function(b: ByteArray): Long = b.size.toLong()
}
impl class Foo : Base()
@@ -0,0 +1,16 @@
-- Common --
Exit code: OK
Output:
-- JVM --
Exit code: COMPILATION_ERROR
Output:
compiler/testData/multiplatform/classScopes/functionIncorrectSignatureFromSuperclass/jvm.kt:5:12: error: 'impl' class 'Foo' has no implementation of 'header' class members:
public final header fun function(b: ByteArray): Int
The following declaration is incompatible because return type is different:
public final fun function(b: ByteArray): Long
impl class Foo : Base()
^
@@ -5,10 +5,7 @@ Output:
-- JVM --
Exit code: COMPILATION_ERROR
Output:
compiler/testData/multiplatform/classScopes/missingConstructor/jvm.kt:1:12: error: 'impl' class 'Foo' has no corresponding 'header' declaration
The following declaration is incompatible because some members are not implemented:
public final header class Foo
No implementations are found for members listed below:
compiler/testData/multiplatform/classScopes/missingConstructor/jvm.kt:1:12: error: 'impl' class 'Foo' has no implementation of 'header' class members:
public constructor Foo(s: String)
@@ -5,10 +5,7 @@ Output:
-- JVM --
Exit code: COMPILATION_ERROR
Output:
compiler/testData/multiplatform/classScopes/missingFunction/jvm.kt:1:12: error: 'impl' class 'Foo' has no corresponding 'header' declaration
The following declaration is incompatible because some members are not implemented:
public final header class Foo
No implementations are found for members listed below:
compiler/testData/multiplatform/classScopes/missingFunction/jvm.kt:1:12: error: 'impl' class 'Foo' has no implementation of 'header' class members:
public final header fun function(s: String): Unit