[FIR] Add diagnostic CONFLICTING_OVERLOADS & REDECLARATION

This commit is contained in:
Nick
2020-08-05 09:35:10 +03:00
parent 36984009e9
commit 4669e019d1
72 changed files with 681 additions and 247 deletions
@@ -2,15 +2,15 @@
@Target(AnnotationTarget.CLASS) @Target(AnnotationTarget.CLASS)
annotation class Ann annotation class Ann
var x: Int <!REDECLARATION!>var x: Int
get() = 1 get() = 1
set(@Ann private x) { } set(@Ann private x) { }<!>
var x: String = "" <!REDECLARATION!>var x: String = ""
set(param: <!REDUNDANT_SETTER_PARAMETER_TYPE!>String<!>) { set(param: <!REDUNDANT_SETTER_PARAMETER_TYPE!>String<!>) {
field = "$param " field = "$param "
} }<!>
class My { class My {
var y: Int = 1 var y: Int = 1
@@ -11,11 +11,11 @@ internal inline fun internal() {
f() f()
} }
class C { <!REDECLARATION!>class C {
internal val z = object { internal val z = object {
fun foo() = 13 fun foo() = 13
} }
} }<!>
class Foo2< class Foo2<
T1, T1,
@@ -27,12 +27,12 @@ class Foo2<
internal inner class B<T,T2,> internal inner class B<T,T2,>
} }
<!REDUNDANT_VISIBILITY_MODIFIER!>public<!> class C { <!REDECLARATION!><!REDUNDANT_VISIBILITY_MODIFIER!>public<!> class C {
<!REDUNDANT_VISIBILITY_MODIFIER!>public<!> val foo: Int = 0 <!REDUNDANT_VISIBILITY_MODIFIER!>public<!> val foo: Int = 0
<!REDUNDANT_VISIBILITY_MODIFIER!>public<!> fun bar() {} <!REDUNDANT_VISIBILITY_MODIFIER!>public<!> fun bar() {}
} }<!>
open class D { open class D {
protected open fun willRemainProtected() { protected open fun willRemainProtected() {
@@ -17,7 +17,7 @@ class LocalFreezableVar<T>(private var value: T) {
} }
class C <!REDECLARATION!>class C<!>
operator fun C.plus(a: Any): C = this operator fun C.plus(a: Any): C = this
operator fun C.plusAssign(a: Any) {} operator fun C.plusAssign(a: Any) {}
@@ -172,14 +172,14 @@ fun notAssignedWhenNotUsed(p: Int) {
var global = 1 var global = 1
class C { <!REDECLARATION!>class C {
var field = 2 var field = 2
fun foo() { fun foo() {
print(field) print(field)
print(global) print(global)
} }
} }<!>
fun withDelegate() { fun withDelegate() {
var s: String by Delegates.notNull() var s: String by Delegates.notNull()
@@ -0,0 +1,68 @@
<!CONFLICTING_OVERLOADS!>fun test(x: Int) {}<!>
<!CONFLICTING_OVERLOADS!>fun test(y: Int) {}<!>
fun test() {}
fun test(z: Int, c: Char) {}
<!REDECLARATION!>open class A {
open fun rest(s: String) {}
open val u = 20
}<!>
<!REDECLARATION!>class A {
}<!>
<!REDECLARATION!>class B : A {
<!CONFLICTING_OVERLOADS!>override fun rest(s: String) {}<!>
<!CONFLICTING_OVERLOADS!>fun rest(s: String) {}<!>
fun rest(l: Long) {}
override val u = 310
}<!>
<!REDECLARATION!>interface B<!>
<!REDECLARATION!>enum class B<!>
<!REDECLARATION!>val u = 10<!>
<!REDECLARATION!>val u = 20<!>
<!REDECLARATION!>typealias TA = A<!>
<!REDECLARATION!>typealias TA = B<!>
typealias BA = A
fun <T> kek(t: T) where T : (String) -> Any?, T : Char {}
fun <T> kek(t: T) where T : () -> Boolean, T : String {}
fun <T : Int> kek(t: T) {}
fun lol(a: Array<Int>) {}
fun lol(a: Array<Boolean>) {}
<!CONFLICTING_OVERLOADS!>fun <T> mem(t: T) where T : () -> Boolean, T : String {}<!>
<!CONFLICTING_OVERLOADS!>fun <T> mem(t: T) where T : String, T : () -> Boolean {}<!>
class M {
companion <!REDECLARATION!>object<!> {}
<!REDECLARATION!>val Companion = object : Any {}<!>
}
fun B.foo() {}
class L {
fun B.foo() {}
}
fun mest()
class mest
fun() {}
private fun() {}
@@ -0,0 +1,124 @@
FILE: conflictingOverloads.kt
public final fun test(x: R|kotlin/Int|): R|kotlin/Unit| {
}
public final fun test(y: R|kotlin/Int|): R|kotlin/Unit| {
}
public final fun test(): R|kotlin/Unit| {
}
public final fun test(z: R|kotlin/Int|, c: R|kotlin/Char|): R|kotlin/Unit| {
}
public open class A : R|kotlin/Any| {
public constructor(): R|A| {
super<R|kotlin/Any|>()
}
public open fun rest(s: R|kotlin/String|): R|kotlin/Unit| {
}
public open val u: R|kotlin/Int| = Int(20)
public get(): R|kotlin/Int|
}
public final class A : R|kotlin/Any| {
public constructor(): R|A| {
super<R|kotlin/Any|>()
}
}
public final class B : R|A| {
public constructor(): R|B| {
super<R|A|>()
}
public final override fun rest(s: R|kotlin/String|): R|kotlin/Unit| {
}
public final fun rest(s: R|kotlin/String|): R|kotlin/Unit| {
}
public final fun rest(l: R|kotlin/Long|): R|kotlin/Unit| {
}
public final override val u: R|kotlin/Int| = Int(310)
public get(): R|kotlin/Int|
}
public abstract interface B : R|kotlin/Any| {
}
public final enum class B : R|kotlin/Enum<B>| {
private constructor(): R|B| {
super<R|kotlin/Enum<B>|>()
}
public final static fun values(): R|kotlin/Array<B>| {
}
public final static fun valueOf(value: R|kotlin/String|): R|B| {
}
}
public final val u: R|kotlin/Int| = Int(10)
public get(): R|kotlin/Int|
public final val u: R|kotlin/Int| = Int(20)
public get(): R|kotlin/Int|
public final typealias TA = R|A|
public final typealias TA = R|B|
public final typealias BA = R|A|
public final fun <T : R|(kotlin/String) -> kotlin/Any?|, R|kotlin/Char|> kek(t: R|T|): R|kotlin/Unit| {
}
public final fun <T : R|() -> kotlin/Boolean|, R|kotlin/String|> kek(t: R|T|): R|kotlin/Unit| {
}
public final fun <T : R|kotlin/Int|> kek(t: R|T|): R|kotlin/Unit| {
}
public final fun lol(a: R|kotlin/Array<kotlin/Int>|): R|kotlin/Unit| {
}
public final fun lol(a: R|kotlin/Array<kotlin/Boolean>|): R|kotlin/Unit| {
}
public final fun <T : R|() -> kotlin/Boolean|, R|kotlin/String|> mem(t: R|T|): R|kotlin/Unit| {
}
public final fun <T : R|kotlin/String|, R|() -> kotlin/Boolean|> mem(t: R|T|): R|kotlin/Unit| {
}
public final class M : R|kotlin/Any| {
public constructor(): R|M| {
super<R|kotlin/Any|>()
}
public final companion object Companion : R|kotlin/Any| {
private constructor(): R|M.Companion| {
super<R|kotlin/Any|>()
}
}
public final val Companion: R|<anonymous>| = object : R|kotlin/Any| {
private constructor(): R|<anonymous>| {
super<R|kotlin/Any|>()
}
}
public get(): R|<anonymous>|
}
public final fun R|B|.foo(): R|kotlin/Unit| {
}
public final class L : R|kotlin/Any| {
public constructor(): R|L| {
super<R|kotlin/Any|>()
}
public final fun R|B|.foo(): R|kotlin/Unit| {
}
}
public final fun mest(): R|kotlin/Unit|
public final class mest : R|kotlin/Any| {
public constructor(): R|mest| {
super<R|kotlin/Any|>()
}
}
public final fun <no name provided>(): R|kotlin/Unit| {
}
private final fun <no name provided>(): R|kotlin/Unit| {
}
@@ -1,9 +1,9 @@
class A { class A {
companion object { companion <!REDECLARATION!>object<!> {
} }
companion <!MANY_COMPANION_OBJECTS!>object<!> { companion <!MANY_COMPANION_OBJECTS, REDECLARATION!>object<!> {
} }
} }
@@ -1,6 +1,6 @@
object A <!REDECLARATION!>object A<!>
val A = 10 <!REDECLARATION!>val A = 10<!>
fun foo() = A fun foo() = A
@@ -1,4 +1,4 @@
fun takeString(s: String) {} <!CONFLICTING_OVERLOADS!>fun takeString(s: String) {}<!>
class Wrapper(val s: String?) { class Wrapper(val s: String?) {
fun withThis() { fun withThis() {
@@ -11,4 +11,4 @@ class Wrapper(val s: String?) {
} }
} }
fun takeString(s: String) {} <!CONFLICTING_OVERLOADS!>fun takeString(s: String) {}<!>
@@ -23,11 +23,11 @@ fun test_2(a: A?) {
} }
} }
fun test_3(x: Any?) { <!CONFLICTING_OVERLOADS!>fun test_3(x: Any?) {
val a = x as? A ?: return val a = x as? A ?: return
a.foo() // Should be OK a.foo() // Should be OK
x.foo() // Should be OK x.foo() // Should be OK
} }<!>
// ----------------- Unstable ----------------- // ----------------- Unstable -----------------
@@ -53,8 +53,8 @@ fun test_2(a: B?) {
} }
} }
fun test_3(x: Any?) { <!CONFLICTING_OVERLOADS!>fun test_3(x: Any?) {
val a = x as? B ?: return val a = x as? B ?: return
a.foo() // Should be OK a.foo() // Should be OK
x.foo() // Should be OK x.foo() // Should be OK
} }<!>
+4 -4
View File
@@ -13,7 +13,7 @@ class B()
class C(val b : B) class C(val b : B)
fun get(f: Boolean) = if (f) {A.A1} else {""} fun get(f: Boolean) = if (f) {A.A1} else {""}
fun case2() { <!CONFLICTING_OVERLOADS!>fun case2() {
val flag: Any = get(false) //string val flag: Any = get(false) //string
val l1 = when (flag!!) { // should be NO_ELSE_IN_WHEN val l1 = when (flag!!) { // should be NO_ELSE_IN_WHEN
@@ -25,9 +25,9 @@ fun case2() {
A.A1 -> B() A.A1 -> B()
A.A2 -> B() A.A2 -> B()
} }
} }<!>
fun case2() { <!CONFLICTING_OVERLOADS!>fun case2() {
val flag: Any = get(true) //A val flag: Any = get(true) //A
val l1 = when (flag!!) {// should be NO_ELSE_IN_WHEN val l1 = when (flag!!) {// should be NO_ELSE_IN_WHEN
@@ -39,7 +39,7 @@ fun case2() {
A.A1 -> B() A.A1 -> B()
A.A2 -> B() A.A2 -> B()
} }
} }<!>
fun case3() { fun case3() {
@@ -1,5 +1,5 @@
fun bar(x: String): Int = 1 <!CONFLICTING_OVERLOADS!>fun bar(x: String): Int = 1<!>
fun bar(x: String): Double = 1 <!CONFLICTING_OVERLOADS!>fun bar(x: String): Double = 1<!>
fun baz(x: String): Int = 1 fun baz(x: String): Int = 1
fun <T, R> foobaz(x: T): R = TODO() fun <T, R> foobaz(x: T): R = TODO()
@@ -1,8 +1,8 @@
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") <!CONFLICTING_OVERLOADS!>@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
<!HIDDEN!>@kotlin.internal.LowPriorityInOverloadResolution<!> <!HIDDEN!>@kotlin.internal.LowPriorityInOverloadResolution<!>
fun foo(): Int = 1 fun foo(): Int = 1<!>
fun foo(): String = "" <!CONFLICTING_OVERLOADS!>fun foo(): String = ""<!>
fun test() { fun test() {
val s = foo() val s = foo()
@@ -13,7 +13,7 @@ fun test() {
val Any.bar get() = "456" val Any.bar get() = "456"
val String.bar get() = "987" val String.bar get() = "987"
val t = "".bar <!REDECLARATION!>val t = "".bar<!>
val p = Pair(0, "") val p = Pair(0, "")
@@ -21,4 +21,4 @@ class Base<T>(val x: T)
class Derived : Base<Int>(10) class Derived : Base<Int>(10)
val xx = Derived().x + 1 val xx = Derived().x + 1
val t = throw AssertionError("") <!REDECLARATION!>val t = throw AssertionError("")<!>
@@ -916,6 +916,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/anonymousObjectByDelegate.kt"); runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/anonymousObjectByDelegate.kt");
} }
@TestMetadata("conflictingOverloads.kt")
public void testConflictingOverloads() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/conflictingOverloads.kt");
}
@TestMetadata("cyclicConstructorDelegationCall.kt") @TestMetadata("cyclicConstructorDelegationCall.kt")
public void testCyclicConstructorDelegationCall() throws Exception { public void testCyclicConstructorDelegationCall() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/cyclicConstructorDelegationCall.kt"); runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/cyclicConstructorDelegationCall.kt");
@@ -916,6 +916,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/anonymousObjectByDelegate.kt"); runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/anonymousObjectByDelegate.kt");
} }
@TestMetadata("conflictingOverloads.kt")
public void testConflictingOverloads() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/conflictingOverloads.kt");
}
@TestMetadata("cyclicConstructorDelegationCall.kt") @TestMetadata("cyclicConstructorDelegationCall.kt")
public void testCyclicConstructorDelegationCall() throws Exception { public void testCyclicConstructorDelegationCall() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/cyclicConstructorDelegationCall.kt"); runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/cyclicConstructorDelegationCall.kt");
@@ -53,25 +53,31 @@ fun FirSession.registerCheckersComponent() {
} }
private class ComposedDeclarationCheckers : DeclarationCheckers() { private class ComposedDeclarationCheckers : DeclarationCheckers() {
override val fileCheckers: List<FirFileChecker>
get() = _fileCheckers
override val declarationCheckers: List<FirBasicDeclarationChecker> override val declarationCheckers: List<FirBasicDeclarationChecker>
get() = _declarationCheckers get() = _declarationCheckers
override val memberDeclarationCheckers: List<FirMemberDeclarationChecker> override val memberDeclarationCheckers: List<FirMemberDeclarationChecker>
get() = _memberDeclarationCheckers get() = _memberDeclarationCheckers
override val regularClassCheckers: List<FirRegularClassChecker>
get() = _regularClassCheckers
override val constructorCheckers: List<FirConstructorChecker> override val constructorCheckers: List<FirConstructorChecker>
get() = _constructorCheckers get() = _constructorCheckers
override val controlFlowAnalyserCheckers: List<FirControlFlowChecker> override val controlFlowAnalyserCheckers: List<FirControlFlowChecker>
get() = _controlFlowAnalyserCheckers get() = _controlFlowAnalyserCheckers
private val _fileCheckers: MutableList<FirFileChecker> = mutableListOf()
private val _declarationCheckers: MutableList<FirBasicDeclarationChecker> = mutableListOf() private val _declarationCheckers: MutableList<FirBasicDeclarationChecker> = mutableListOf()
private val _memberDeclarationCheckers: MutableList<FirMemberDeclarationChecker> = mutableListOf() private val _memberDeclarationCheckers: MutableList<FirMemberDeclarationChecker> = mutableListOf()
private val _regularClassCheckers: MutableList<FirRegularClassChecker> = mutableListOf()
private val _constructorCheckers: MutableList<FirConstructorChecker> = mutableListOf() private val _constructorCheckers: MutableList<FirConstructorChecker> = mutableListOf()
private val _controlFlowAnalyserCheckers: MutableList<FirControlFlowChecker> = mutableListOf() private val _controlFlowAnalyserCheckers: MutableList<FirControlFlowChecker> = mutableListOf()
fun register(checkers: DeclarationCheckers) { fun register(checkers: DeclarationCheckers) {
_fileCheckers += checkers.allFileCheckers
_declarationCheckers += checkers.declarationCheckers _declarationCheckers += checkers.declarationCheckers
_memberDeclarationCheckers += checkers.allMemberDeclarationCheckers _memberDeclarationCheckers += checkers.allMemberDeclarationCheckers
_regularClassCheckers += checkers.allRegularClassCheckers
_constructorCheckers += checkers.allConstructorCheckers _constructorCheckers += checkers.allConstructorCheckers
_controlFlowAnalyserCheckers += checkers.controlFlowAnalyserCheckers _controlFlowAnalyserCheckers += checkers.controlFlowAnalyserCheckers
} }
@@ -0,0 +1,146 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.fir.analysis.checkers
import org.jetbrains.kotlin.fir.FirFakeSourceElementKind
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.symbols.CallableId
import org.jetbrains.kotlin.fir.types.FirErrorTypeRef
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.Name
private open class RepresentationBuilder {
var receiver = ""
var name = ""
open fun build() = "[$receiver] $name"
}
private fun buildRepresentation(init: RepresentationBuilder.() -> Unit): String {
return RepresentationBuilder().apply(init).build()
}
private class FunctionRepresentationBuilder : RepresentationBuilder() {
var typeArguments = ""
var parameters = ""
override fun build() = "<$typeArguments> [$receiver] $name ($parameters)"
}
private fun buildFunctionRepresentation(init: FunctionRepresentationBuilder.() -> Unit): String {
return FunctionRepresentationBuilder().apply(init).build()
}
private fun ClassId.represent() = packageFqName.asString() + '/' + relativeClassName.asString()
private fun CallableId.represent() = if (className != null) {
packageName.asString() + '/' + className + '.' + callableName
} else {
packageName.asString() + '/' + callableName
}
private fun FirTypeRef.represent() = when (this) {
is FirResolvedTypeRef -> type.toString()
is FirErrorTypeRef -> "ERROR"
else -> "?"
}
private fun FirTypeParameter.represent() = name.asString() + " : " + bounds
.map { it.represent() }
.sorted()
.joinToString()
private fun FirValueParameter.represent(): String {
val prefix = if (this.isVararg) "vararg " else ""
return prefix + " " + this.returnTypeRef.represent()
}
private fun FirProperty.represent() = buildRepresentation {
receiver = receiverTypeRef?.represent() ?: ""
name = symbol.callableId.represent()
}
private fun FirSimpleFunction.represent() = buildFunctionRepresentation {
typeArguments = typeParameters.joinToString { it.represent() }
receiver = receiverTypeRef?.represent() ?: ""
name = symbol.callableId.represent()
parameters = valueParameters.joinToString { it.represent() }
}
private fun FirTypeAlias.represent() = buildRepresentation {
name = symbol.classId.represent()
}
private fun FirRegularClass.represent() = buildRepresentation {
name = symbol.classId.represent()
}
private val NO_NAME_PROVIDED = Name.special("<no name provided>")
// - see testEnumValuesValueOf.
// it generates a static function that has
// the same signature as the function defined
// explicitly.
// - see tests with `fun () {}`.
// you can't redeclare something that has no name.
private fun FirDeclaration.isCollectable() = when (this) {
is FirSimpleFunction -> source?.kind !is FirFakeSourceElementKind && name != NO_NAME_PROVIDED
is FirRegularClass -> name != NO_NAME_PROVIDED
else -> true
}
class FirDeclarationInspector {
val otherDeclarations = mutableMapOf<String, MutableList<FirDeclaration>>()
val functionDeclarations = mutableMapOf<String, MutableList<FirSimpleFunction>>()
fun collect(declaration: FirDeclaration) {
if (!declaration.isCollectable()) {
return
}
if (declaration is FirSimpleFunction) {
return collectFunction(declaration)
}
val key = when (declaration) {
is FirRegularClass -> declaration.represent()
is FirTypeAlias -> declaration.represent()
is FirProperty -> declaration.represent()
else -> return
}
var value = otherDeclarations[key]
if (value == null) {
value = mutableListOf()
otherDeclarations[key] = value
}
value.add(declaration)
}
private fun collectFunction(declaration: FirSimpleFunction) {
val key = declaration.represent()
var value = functionDeclarations[key]
if (value == null) {
value = mutableListOf()
functionDeclarations[key] = value
}
value.add(declaration)
}
private fun contains(declaration: FirDeclaration) = when (declaration) {
is FirSimpleFunction -> declaration.represent() in functionDeclarations
is FirRegularClass -> declaration.represent() in otherDeclarations
is FirTypeAlias -> declaration.represent() in otherDeclarations
is FirProperty -> declaration.represent() in otherDeclarations
else -> false
}
}
@@ -12,11 +12,15 @@ abstract class DeclarationCheckers {
val EMPTY: DeclarationCheckers = object : DeclarationCheckers() {} val EMPTY: DeclarationCheckers = object : DeclarationCheckers() {}
} }
open val fileCheckers: List<FirFileChecker> = emptyList()
open val declarationCheckers: List<FirBasicDeclarationChecker> = emptyList() open val declarationCheckers: List<FirBasicDeclarationChecker> = emptyList()
open val memberDeclarationCheckers: List<FirMemberDeclarationChecker> = emptyList() open val memberDeclarationCheckers: List<FirMemberDeclarationChecker> = emptyList()
open val regularClassCheckers: List<FirRegularClassChecker> = emptyList()
open val constructorCheckers: List<FirConstructorChecker> = emptyList() open val constructorCheckers: List<FirConstructorChecker> = emptyList()
open val controlFlowAnalyserCheckers: List<FirControlFlowChecker> = emptyList() open val controlFlowAnalyserCheckers: List<FirControlFlowChecker> = emptyList()
internal val allFileCheckers: List<FirFileChecker> get() = fileCheckers + declarationCheckers
internal val allMemberDeclarationCheckers: List<FirMemberDeclarationChecker> get() = memberDeclarationCheckers + declarationCheckers internal val allMemberDeclarationCheckers: List<FirMemberDeclarationChecker> get() = memberDeclarationCheckers + declarationCheckers
internal val allRegularClassCheckers: List<FirRegularClassChecker> get() = regularClassCheckers + allMemberDeclarationCheckers
internal val allConstructorCheckers: List<FirConstructorChecker> get() = constructorCheckers + allMemberDeclarationCheckers internal val allConstructorCheckers: List<FirConstructorChecker> get() = constructorCheckers + allMemberDeclarationCheckers
} }
@@ -9,12 +9,17 @@ import org.jetbrains.kotlin.fir.analysis.cfa.FirPropertyInitializationAnalyzer
import org.jetbrains.kotlin.fir.analysis.checkers.cfa.FirControlFlowChecker import org.jetbrains.kotlin.fir.analysis.checkers.cfa.FirControlFlowChecker
object CommonDeclarationCheckers : DeclarationCheckers() { object CommonDeclarationCheckers : DeclarationCheckers() {
override val fileCheckers: List<FirFileChecker> = listOf(
)
override val declarationCheckers: List<FirBasicDeclarationChecker> = listOf( override val declarationCheckers: List<FirBasicDeclarationChecker> = listOf(
FirAnnotationClassDeclarationChecker, FirAnnotationClassDeclarationChecker,
FirModifierChecker, FirModifierChecker,
FirManyCompanionObjectsChecker, FirManyCompanionObjectsChecker,
FirLocalEntityNotAllowedChecker, FirLocalEntityNotAllowedChecker,
FirTypeParametersInObjectChecker, FirTypeParametersInObjectChecker,
FirConflictsChecker,
) )
override val memberDeclarationCheckers: List<FirMemberDeclarationChecker> = listOf( override val memberDeclarationCheckers: List<FirMemberDeclarationChecker> = listOf(
@@ -26,6 +31,10 @@ object CommonDeclarationCheckers : DeclarationCheckers() {
FirPrimaryConstructorRequiredForDataClassChecker, FirPrimaryConstructorRequiredForDataClassChecker,
) )
override val regularClassCheckers: List<FirRegularClassChecker> = listOf(
)
override val constructorCheckers: List<FirConstructorChecker> = listOf( override val constructorCheckers: List<FirConstructorChecker> = listOf(
FirConstructorAllowedChecker, FirConstructorAllowedChecker,
) )
@@ -0,0 +1,67 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.fir.analysis.checkers.FirDeclarationInspector
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
import org.jetbrains.kotlin.fir.declarations.FirFile
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
object FirConflictsChecker : FirBasicDeclarationChecker() {
override fun check(declaration: FirDeclaration, context: CheckerContext, reporter: DiagnosticReporter) {
val inspector = FirDeclarationInspector()
when (declaration) {
is FirFile -> checkFile(declaration, inspector)
is FirRegularClass -> checkRegularClass(declaration, inspector)
else -> return
}
inspector.functionDeclarations.forEachNonSingle { it, hint ->
reporter.reportConflictingOverloads(it.source, hint)
}
inspector.otherDeclarations.forEachNonSingle { it, hint ->
reporter.reportConflictingDeclarations(it.source, hint)
}
}
private fun Map<String, List<FirDeclaration>>.forEachNonSingle(action: (FirDeclaration, String) -> Unit) {
for (value in values) {
if (value.size > 1) {
val hint = value.joinToString { that -> that.toString() }
value.forEach {
action(it, hint)
}
}
}
}
private fun checkFile(declaration: FirFile, inspector: FirDeclarationInspector) {
for (it in declaration.declarations) {
inspector.collect(it)
}
}
private fun checkRegularClass(declaration: FirRegularClass, inspector: FirDeclarationInspector) {
for (it in declaration.declarations) {
inspector.collect(it)
}
}
private fun DiagnosticReporter.reportConflictingOverloads(source: FirSourceElement?, declarations: String) {
source?.let { report(FirErrors.CONFLICTING_OVERLOADS.on(it, declarations)) }
}
private fun DiagnosticReporter.reportConflictingDeclarations(source: FirSourceElement?, declarations: String) {
source?.let { report(FirErrors.REDECLARATION.on(it, declarations)) }
}
}
@@ -7,15 +7,14 @@ package org.jetbrains.kotlin.fir.analysis.checkers.declaration
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.declarations.FirConstructor import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
abstract class FirDeclarationChecker<in D : FirDeclaration> { abstract class FirDeclarationChecker<in D : FirDeclaration> {
abstract fun check(declaration: D, context: CheckerContext, reporter: DiagnosticReporter) abstract fun check(declaration: D, context: CheckerContext, reporter: DiagnosticReporter)
} }
typealias FirFileChecker = FirDeclarationChecker<FirFile>
typealias FirBasicDeclarationChecker = FirDeclarationChecker<FirDeclaration> typealias FirBasicDeclarationChecker = FirDeclarationChecker<FirDeclaration>
typealias FirMemberDeclarationChecker = FirDeclarationChecker<FirMemberDeclaration> typealias FirMemberDeclarationChecker = FirDeclarationChecker<FirMemberDeclaration>
typealias FirRegularClassChecker = FirDeclarationChecker<FirRegularClass>
typealias FirConstructorChecker = FirDeclarationChecker<FirConstructor> typealias FirConstructorChecker = FirDeclarationChecker<FirConstructor>
@@ -14,10 +14,7 @@ import org.jetbrains.kotlin.fir.analysis.checkers.getModifierList
import org.jetbrains.kotlin.fir.analysis.checkers.source import org.jetbrains.kotlin.fir.analysis.checkers.source
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.declarations.FirClass import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
import org.jetbrains.kotlin.fir.declarations.FirProperty
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyAccessor import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyAccessor
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
import org.jetbrains.kotlin.lexer.KtTokens.* import org.jetbrains.kotlin.lexer.KtTokens.*
@@ -167,6 +164,8 @@ object FirModifierChecker : FirBasicDeclarationChecker() {
} }
override fun check(declaration: FirDeclaration, context: CheckerContext, reporter: DiagnosticReporter) { override fun check(declaration: FirDeclaration, context: CheckerContext, reporter: DiagnosticReporter) {
if (declaration is FirFile) return
val source = declaration.source ?: return val source = declaration.source ?: return
if (!isDeclarationMappedToSourceCorrectly(declaration, source)) return if (!isDeclarationMappedToSourceCorrectly(declaration, source)) return
if (context.containingDeclarations.last() is FirDefaultPropertyAccessor) return if (context.containingDeclarations.last() is FirDefaultPropertyAccessor) return
@@ -17,12 +17,16 @@ class DeclarationCheckersDiagnosticComponent(
) : AbstractDiagnosticCollectorComponent(collector) { ) : AbstractDiagnosticCollectorComponent(collector) {
private val checkers = session.checkersComponent.declarationCheckers private val checkers = session.checkersComponent.declarationCheckers
override fun visitFile(file: FirFile, data: CheckerContext) {
runCheck { checkers.fileCheckers.check(file, data, it) }
}
override fun visitProperty(property: FirProperty, data: CheckerContext) { override fun visitProperty(property: FirProperty, data: CheckerContext) {
runCheck { checkers.memberDeclarationCheckers.check(property, data, it) } runCheck { checkers.memberDeclarationCheckers.check(property, data, it) }
} }
override fun visitRegularClass(regularClass: FirRegularClass, data: CheckerContext) { override fun visitRegularClass(regularClass: FirRegularClass, data: CheckerContext) {
runCheck { checkers.memberDeclarationCheckers.check(regularClass, data, it) } runCheck { checkers.regularClassCheckers.check(regularClass, data, it) }
} }
override fun visitSimpleFunction(simpleFunction: FirSimpleFunction, data: CheckerContext) { override fun visitSimpleFunction(simpleFunction: FirSimpleFunction, data: CheckerContext) {
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ANNOTATION_CLASS_
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ANNOTATION_PARAMETER_DEFAULT_VALUE_MUST_BE_CONSTANT import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ANNOTATION_PARAMETER_DEFAULT_VALUE_MUST_BE_CONSTANT
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ASSIGN_OPERATOR_AMBIGUITY import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ASSIGN_OPERATOR_AMBIGUITY
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.BREAK_OR_CONTINUE_OUTSIDE_A_LOOP import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.BREAK_OR_CONTINUE_OUTSIDE_A_LOOP
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.CONFLICTING_OVERLOADS
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.CONSTRUCTOR_IN_INTERFACE import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.CONSTRUCTOR_IN_INTERFACE
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.CONSTRUCTOR_IN_OBJECT import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.CONSTRUCTOR_IN_OBJECT
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.CYCLIC_CONSTRUCTOR_DELEGATION_CALL import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.CYCLIC_CONSTRUCTOR_DELEGATION_CALL
@@ -65,6 +66,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.PROJECTION_ON_NON
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.QUALIFIED_SUPERTYPE_EXTENDED_BY_OTHER_SUPERTYPE import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.QUALIFIED_SUPERTYPE_EXTENDED_BY_OTHER_SUPERTYPE
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.RECURSION_IN_IMPLICIT_TYPES import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.RECURSION_IN_IMPLICIT_TYPES
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.RECURSION_IN_SUPERTYPES import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.RECURSION_IN_SUPERTYPES
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.REDECLARATION
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.REDUNDANT_MODIFIER import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.REDUNDANT_MODIFIER
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.REPEATED_MODIFIER import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.REPEATED_MODIFIER
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.RETURN_NOT_ALLOWED import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.RETURN_NOT_ALLOWED
@@ -193,6 +195,8 @@ class FirDefaultErrorMessages : DefaultErrorMessages.Extension {
// Redeclarations // Redeclarations
map.put(MANY_COMPANION_OBJECTS, "Only one companion object is allowed per class") map.put(MANY_COMPANION_OBJECTS, "Only one companion object is allowed per class")
map.put(CONFLICTING_OVERLOADS, "Conflicting overloads: {0}", TO_STRING) // *
map.put(REDECLARATION, "Conflicting declarations: {0}", TO_STRING) // *
// Invalid local declarations // Invalid local declarations
map.put(LOCAL_OBJECT_NOT_ALLOWED, "Named object ''{0}'' is a singleton and cannot be local. Try to use anonymous object instead", TO_STRING) // + map.put(LOCAL_OBJECT_NOT_ALLOWED, "Named object ''{0}'' is a singleton and cannot be local. Try to use anonymous object instead", TO_STRING) // +
@@ -118,6 +118,8 @@ object FirErrors {
// Redeclarations // Redeclarations
val MANY_COMPANION_OBJECTS by error0<FirSourceElement, PsiElement>() val MANY_COMPANION_OBJECTS by error0<FirSourceElement, PsiElement>()
val CONFLICTING_OVERLOADS by error1<FirSourceElement, PsiElement, String>()
val REDECLARATION by error1<FirSourceElement, PsiElement, String>()
// Invalid local declarations // Invalid local declarations
val LOCAL_OBJECT_NOT_ALLOWED by error1<FirSourceElement, PsiElement, Name>() val LOCAL_OBJECT_NOT_ALLOWED by error1<FirSourceElement, PsiElement, Name>()
@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.fir.symbols.StandardClassIds
fun ConeTypeProjection.createArrayOf(nullable: Boolean = false): ConeKotlinType { fun ConeTypeProjection.createArrayOf(nullable: Boolean = false): ConeKotlinType {
if (this is ConeKotlinTypeProjection) { if (this is ConeKotlinTypeProjection) {
val type = type.lowerBoundIfFlexible() val type = type.lowerBoundIfFlexible()
if (type is ConeClassLikeType) { if (type is ConeClassLikeType && type.nullability != ConeNullability.NULLABLE) {
val classId = type.lookupTag.classId val classId = type.lookupTag.classId
val primitiveArrayId = val primitiveArrayId =
StandardClassIds.primitiveArrayTypeByElementType[classId] ?: StandardClassIds.unsignedArrayTypeByElementType[classId] StandardClassIds.primitiveArrayTypeByElementType[classId] ?: StandardClassIds.unsignedArrayTypeByElementType[classId]
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// WITH_RUNTIME // WITH_RUNTIME
// KJS_WITH_FULL_RUNTIME // KJS_WITH_FULL_RUNTIME
@@ -2,10 +2,10 @@
package Jet86 package Jet86
class A { class A {
companion object { companion <!REDECLARATION!>object<!> {
val x = 1 val x = 1
} }
companion <!MANY_COMPANION_OBJECTS!>object<!> { companion <!MANY_COMPANION_OBJECTS, REDECLARATION!>object<!> {
val x = 1 val x = 1
} }
} }
@@ -2,19 +2,19 @@
package test package test
class A { class A {
object Companion <!REDECLARATION!>object Companion<!>
companion object companion <!REDECLARATION!>object<!>
} }
class B { class B {
companion object Named companion <!REDECLARATION!>object Named<!>
object Named <!REDECLARATION!>object Named<!>
} }
class C { class C {
class Named <!REDECLARATION!>class Named<!>
companion object Named companion <!REDECLARATION!>object Named<!>
} }
@@ -1,6 +1,6 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER // !DIAGNOSTICS: -UNUSED_PARAMETER
data class A(val x: Int, val y: String) { data class A(val x: Int, val y: String) {
fun copy(x: Int, y: String) = x <!CONFLICTING_OVERLOADS!>fun copy(x: Int, y: String) = x<!>
fun copy(x: Int, y: String) = A(x, y) <!CONFLICTING_OVERLOADS!>fun copy(x: Int, y: String) = A(x, y)<!>
} }
@@ -1,9 +1,9 @@
data class A1(val x: Int, val y: String, val x: Int) { data class A1(<!REDECLARATION!>val x: Int<!>, val y: String, <!REDECLARATION!>val x: Int<!>) {
val z = "" val z = ""
} }
data class A2(val x: Int, val y: String) { data class A2(<!REDECLARATION!>val x: Int<!>, val y: String) {
val x = "" <!REDECLARATION!>val x = ""<!>
} }
data class A3(val<!SYNTAX!><!> :Int, val<!SYNTAX!><!> : Int) data class A3(<!REDECLARATION!>val<!SYNTAX!><!> :Int<!>, <!REDECLARATION!>val<!SYNTAX!><!> : Int<!>)
@@ -7,8 +7,8 @@ class MyClass {
class MyClass2 {} class MyClass2 {}
fun MyClass2.component1() = 1.2 <!CONFLICTING_OVERLOADS!>fun MyClass2.component1() = 1.2<!>
fun MyClass2.component1() = 1.3 <!CONFLICTING_OVERLOADS!>fun MyClass2.component1() = 1.3<!>
fun test(mc1: MyClass, mc2: MyClass2) { fun test(mc1: MyClass, mc2: MyClass2) {
val (<!INAPPLICABLE_CANDIDATE!>a<!>, <!UNRESOLVED_REFERENCE!>b<!>) = mc1 val (<!INAPPLICABLE_CANDIDATE!>a<!>, <!UNRESOLVED_REFERENCE!>b<!>) = mc1
@@ -1,6 +1,6 @@
class A { class A {
operator fun component1() = 1 <!CONFLICTING_OVERLOADS!>operator fun component1() = 1<!>
operator fun component1() = 1 <!CONFLICTING_OVERLOADS!>operator fun component1() = 1<!>
operator fun component2() = 1 operator fun component2() = 1
} }
@@ -3,10 +3,10 @@
// KT-3464 Front-end shouldn't allow override modifier in class declaration // KT-3464 Front-end shouldn't allow override modifier in class declaration
override class A { override class A {
override companion object {} override companion <!REDECLARATION!>object<!> {}
open companion <!MANY_COMPANION_OBJECTS!>object<!> {} open companion <!MANY_COMPANION_OBJECTS, REDECLARATION!>object<!> {}
abstract companion <!MANY_COMPANION_OBJECTS!>object<!> {} abstract companion <!MANY_COMPANION_OBJECTS, REDECLARATION!>object<!> {}
final companion <!MANY_COMPANION_OBJECTS!>object<!> {} final companion <!MANY_COMPANION_OBJECTS, REDECLARATION!>object<!> {}
} }
override object B1 {} override object B1 {}
@@ -1,5 +1,5 @@
class C { class C {
companion object {} companion <!REDECLARATION!>object<!> {}
val Companion = C <!REDECLARATION!>val Companion = C<!>
} }
@@ -1,8 +1,8 @@
class B { class B {
companion object A { companion <!REDECLARATION!>object A<!> {
} }
val A = this <!REDECLARATION!>val A = this<!>
} }
class C { class C {
@@ -10,5 +10,5 @@ fun test1(a: Array<out Int?>) {
fun test2(vararg a: Int?) { fun test2(vararg a: Int?) {
val list = a.<!INAPPLICABLE_CANDIDATE!>filterNotNull<!>() val list = a.<!INAPPLICABLE_CANDIDATE!>filterNotNull<!>()
list checkType { <!INAPPLICABLE_CANDIDATE!>_<!><List<Int>>() } list checkType { _<List<Int>>() }
} }
@@ -15,15 +15,15 @@ inline operator fun <T, U, V> @ExtensionFunctionType Function2<T, U, V>.plus(p:
this - p this - p
} }
inline fun <T, U, V> inlineFunWithInvoke(s: (p: T) -> U, ext: T.(p: U) -> V) { <!CONFLICTING_OVERLOADS!>inline fun <T, U, V> inlineFunWithInvoke(s: (p: T) -> U, ext: T.(p: U) -> V) {
s + s s + s
ext + ext ext + ext
} }<!>
inline fun <T, U, V> inlineFunWithInvoke(s: (p: T) -> U, ext: T.(p: U) -> V) { <!CONFLICTING_OVERLOADS!>inline fun <T, U, V> inlineFunWithInvoke(s: (p: T) -> U, ext: T.(p: U) -> V) {
s + s s + s
ext + ext ext + ext
} }<!>
inline fun <T, U> Function1<T, U>.submit() { inline fun <T, U> Function1<T, U>.submit() {
this + this this + this
@@ -23,6 +23,6 @@ actual var s: String = "value"
fun foo2(): Int = 0 fun foo2(): Int = 0
actual class Foo3 <!REDECLARATION!>actual class Foo3<!>
class Foo3 <!REDECLARATION!>class Foo3<!>
@@ -1,8 +0,0 @@
// !LANGUAGE: +MultiPlatformProjects
// MODULE: m1-common
// FILE: common.kt
expect fun foo()
expect fun foo()
expect fun foo(x: Int)
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +MultiPlatformProjects // !LANGUAGE: +MultiPlatformProjects
// MODULE: m1-common // MODULE: m1-common
// FILE: common.kt // FILE: common.kt
@@ -7,11 +7,11 @@ expect fun foo()
// MODULE: m2-jvm(m1-common) // MODULE: m2-jvm(m1-common)
// FILE: jvm.kt // FILE: jvm.kt
actual fun foo() {} <!CONFLICTING_OVERLOADS!>actual fun foo() {}<!>
actual fun foo() {} <!CONFLICTING_OVERLOADS!>actual fun foo() {}<!>
// MODULE: m3-js(m1-common) // MODULE: m3-js(m1-common)
// FILE: js.kt // FILE: js.kt
actual fun foo() {} <!CONFLICTING_OVERLOADS!>actual fun foo() {}<!>
actual fun foo() {} <!CONFLICTING_OVERLOADS!>actual fun foo() {}<!>
@@ -2,8 +2,8 @@
// MODULE: m1-common // MODULE: m1-common
// FILE: common.kt // FILE: common.kt
expect fun foo() <!CONFLICTING_OVERLOADS!>expect fun foo()<!>
expect fun foo() {} <!CONFLICTING_OVERLOADS!>expect fun foo() {}<!>
expect fun bar() {} expect fun bar() {}
@@ -1,6 +1,6 @@
class A { class A {
fun a(a: Int): Int = 0 <!CONFLICTING_OVERLOADS!>fun a(a: Int): Int = 0<!>
fun a(a: Int) { <!CONFLICTING_OVERLOADS!>fun a(a: Int) {
} }<!>
} }
@@ -1,7 +1,7 @@
package qwertyuiop package qwertyuiop
fun c(s: String) { <!CONFLICTING_OVERLOADS!>fun c(s: String) {
} }<!>
fun c(s: String) { <!CONFLICTING_OVERLOADS!>fun c(s: String) {
} }<!>
@@ -1,5 +1,5 @@
package extensionFunctions package extensionFunctions
fun Int.qwe(a: Float) = 1 <!CONFLICTING_OVERLOADS!>fun Int.qwe(a: Float) = 1<!>
fun Int.qwe(a: Float) = 2 <!CONFLICTING_OVERLOADS!>fun Int.qwe(a: Float) = 2<!>
@@ -1,7 +1,7 @@
class A() { class A() {
fun b() { <!CONFLICTING_OVERLOADS!>fun b() {
} }<!>
fun b() { <!CONFLICTING_OVERLOADS!>fun b() {
} }<!>
} }
@@ -1,4 +1,4 @@
class Aaa() { class Aaa() {
val a = 1 <!REDECLARATION!>val a = 1<!>
val a = 1 <!REDECLARATION!>val a = 1<!>
} }
@@ -1,4 +1,4 @@
class Aaa() { class Aaa() {
val a = 1 <!REDECLARATION!>val a = 1<!>
val a = "" <!REDECLARATION!>val a = ""<!>
} }
@@ -1,8 +1,8 @@
import java.io.Serializable import java.io.Serializable
interface Test1 { interface Test1 {
fun <T> foo(t: T) where T : Cloneable, T : Serializable <!CONFLICTING_OVERLOADS!>fun <T> foo(t: T) where T : Cloneable, T : Serializable<!>
fun <T> foo(t: T) where T : Serializable, T : Cloneable <!CONFLICTING_OVERLOADS!>fun <T> foo(t: T) where T : Serializable, T : Cloneable<!>
} }
@@ -10,6 +10,6 @@ interface I1
interface I2 : I1 interface I2 : I1
interface Test2 { interface Test2 {
fun <T> foo(t: T) where T : I1, T : I2 <!CONFLICTING_OVERLOADS!>fun <T> foo(t: T) where T : I1, T : I2<!>
fun <T> foo(t: T) where T : I2, T : I1 <!CONFLICTING_OVERLOADS!>fun <T> foo(t: T) where T : I2, T : I1<!>
} }
@@ -3,6 +3,6 @@ interface Some {
} }
class SomeImpl : Some { class SomeImpl : Some {
override fun test() {} <!CONFLICTING_OVERLOADS!>override fun test() {}<!>
override fun test() {} <!CONFLICTING_OVERLOADS!>override fun test() {}<!>
} }
@@ -1,4 +1,4 @@
package foo package foo
val Int.foo: Int get() = 2 <!REDECLARATION!>val Int.foo: Int get() = 2<!>
val Int.foo: Int get() = 3 <!REDECLARATION!>val Int.foo: Int get() = 3<!>
@@ -1,13 +1,13 @@
public class A() { public class A() {
public val FOO: String = "test" <!REDECLARATION!>public val FOO: String = "test"<!>
public class FOO() { } <!REDECLARATION!>public class FOO() { }<!>
} }
public class B() { public class B() {
companion object { companion object {
public val FOO: String = "test" <!REDECLARATION!>public val FOO: String = "test"<!>
public class FOO() { } <!REDECLARATION!>public class FOO() { }<!>
} }
} }
@@ -1,6 +1,6 @@
class A { class A {
companion object B { companion object B {
class G <!REDECLARATION!>class G<!>
val G = 1 <!REDECLARATION!>val G = 1<!>
} }
} }
@@ -1,5 +1,5 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER // !DIAGNOSTICS: -UNUSED_PARAMETER
// KT-9733 No error shown for 2 "main" functions in the same file // KT-9733 No error shown for 2 "main" functions in the same file
fun main(args: Array<String>) {} <!CONFLICTING_OVERLOADS!>fun main(args: Array<String>) {}<!>
fun main(args: Array<String>) {} <!CONFLICTING_OVERLOADS!>fun main(args: Array<String>) {}<!>
@@ -1,14 +1,14 @@
// FILE: f.kt // FILE: f.kt
package redeclarations package redeclarations
object A { <!REDECLARATION!>object A<!> {
val x : Int = 0 val x : Int = 0
val A = 1 val A = 1
} }
class A {} <!REDECLARATION!>class A {}<!>
val A = 1 <!REDECLARATION!>val A = 1<!>
// FILE: f.kt // FILE: f.kt
package redeclarations.A package redeclarations.A
@@ -1,9 +1,9 @@
// !DIAGNOSTICS: -DUPLICATE_CLASS_NAMES // !DIAGNOSTICS: -DUPLICATE_CLASS_NAMES
// KT-3525 // KT-3525
object B { object B {
class C <!REDECLARATION!>class C<!>
class C <!REDECLARATION!>class C<!>
val a : Int = 1 <!REDECLARATION!>val a : Int = 1<!>
val a : Int = 1 <!REDECLARATION!>val a : Int = 1<!>
} }
@@ -14,16 +14,16 @@ private val invalidProp0 = 1
fun useInvalidFun0() = invalidFun0() fun useInvalidFun0() = invalidFun0()
fun useInvalidProp0() = invalidProp0 fun useInvalidProp0() = invalidProp0
private fun invalidFun1() {} <!CONFLICTING_OVERLOADS!>private fun invalidFun1() {}<!>
private fun invalidFun1() {} <!CONFLICTING_OVERLOADS!>private fun invalidFun1() {}<!>
private fun invalidFun2() {} <!CONFLICTING_OVERLOADS!>private fun invalidFun2() {}<!>
public fun invalidFun2() {} <!CONFLICTING_OVERLOADS!>public fun invalidFun2() {}<!>
public fun invalidFun3() {} public fun invalidFun3() {}
private fun invalidFun4() {} <!CONFLICTING_OVERLOADS!>private fun invalidFun4() {}<!>
public fun invalidFun4() {} <!CONFLICTING_OVERLOADS!>public fun invalidFun4() {}<!>
public fun validFun2(a: A) = a public fun validFun2(a: A) = a
public fun validFun2(b: B) = b public fun validFun2(b: B) = b
@@ -1,13 +1,13 @@
val Test1 = null <!REDECLARATION!>val Test1 = null<!>
class Test1 <!REDECLARATION!>class Test1<!>
val Test2 = null <!REDECLARATION!>val Test2 = null<!>
interface Test2 <!REDECLARATION!>interface Test2<!>
val Test3 = null <!REDECLARATION!>val Test3 = null<!>
object Test3 <!REDECLARATION!>object Test3<!>
val Test4 = null <!REDECLARATION!>val Test4 = null<!>
class Test4 <!REDECLARATION!>class Test4<!>
interface Test4 <!REDECLARATION!>interface Test4<!>
object Test4 <!REDECLARATION!>object Test4<!>
@@ -1,17 +1,17 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY // !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY
// FILE: file1.kt // FILE: file1.kt
class SomeClass <!REDECLARATION!>class SomeClass<!>
typealias SomeClass = Any <!REDECLARATION!>typealias SomeClass = Any<!>
typealias SomeClass = Any <!REDECLARATION!>typealias SomeClass = Any<!>
typealias SomeClass = Any <!REDECLARATION!>typealias SomeClass = Any<!>
class Outer { class Outer {
class Nested <!REDECLARATION!>class Nested<!>
typealias Nested = Any <!REDECLARATION!>typealias Nested = Any<!>
typealias Nested = Any <!REDECLARATION!>typealias Nested = Any<!>
typealias Nested = Any <!REDECLARATION!>typealias Nested = Any<!>
} }
// FILE: file2.kt // FILE: file2.kt
@@ -1,13 +1,13 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY // !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -TOPLEVEL_TYPEALIASES_ONLY
// FILE: file1.kt // FILE: file1.kt
typealias Test = String <!REDECLARATION!>typealias Test = String<!>
val Test = 42 <!REDECLARATION!>val Test = 42<!>
class Outer { class Outer {
typealias Test = String <!REDECLARATION!>typealias Test = String<!>
val Test = 42 <!REDECLARATION!>val Test = 42<!>
} }
typealias Test2 = String typealias Test2 = String
@@ -4,19 +4,19 @@
package kt2438 package kt2438
class B { class B {
class C <!REDECLARATION!>class C<!>
class C <!REDECLARATION!>class C<!>
} }
class A { class A {
class B <!REDECLARATION!>class B<!>
companion object { companion object {
class B <!REDECLARATION!>class B<!>
class B <!REDECLARATION!>class B<!>
} }
class B <!REDECLARATION!>class B<!>
} }
@@ -1,37 +1,37 @@
val a : Int = 1 <!REDECLARATION!>val a : Int = 1<!>
val a : Int = 1 <!REDECLARATION!>val a : Int = 1<!>
val a : Int = 1 <!REDECLARATION!>val a : Int = 1<!>
val b : Int = 1 <!REDECLARATION!>val b : Int = 1<!>
val b : Int = 1 <!REDECLARATION!>val b : Int = 1<!>
val b : Int = 1 <!REDECLARATION!>val b : Int = 1<!>
val b : Int = 1 <!REDECLARATION!>val b : Int = 1<!>
fun foo() {} // and here too <!CONFLICTING_OVERLOADS!>fun foo() {}<!> // and here too
fun foo() {} // and here <!CONFLICTING_OVERLOADS!>fun foo() {}<!> // and here
fun foo() {} // and here <!CONFLICTING_OVERLOADS!>fun foo() {}<!> // and here
fun foo() {} // and here <!CONFLICTING_OVERLOADS!>fun foo() {}<!> // and here
fun bar() {} // and here <!CONFLICTING_OVERLOADS!>fun bar() {}<!> // and here
fun bar() {} // and here <!CONFLICTING_OVERLOADS!>fun bar() {}<!> // and here
fun bar() {} // and here <!CONFLICTING_OVERLOADS!>fun bar() {}<!> // and here
class A { class A {
val a : Int = 1 <!REDECLARATION!>val a : Int = 1<!>
val a : Int = 1 <!REDECLARATION!>val a : Int = 1<!>
val a : Int = 1 <!REDECLARATION!>val a : Int = 1<!>
val b : Int = 1 <!REDECLARATION!>val b : Int = 1<!>
val b : Int = 1 <!REDECLARATION!>val b : Int = 1<!>
val b : Int = 1 <!REDECLARATION!>val b : Int = 1<!>
val b : Int = 1 <!REDECLARATION!>val b : Int = 1<!>
fun foo() {} // and here too <!CONFLICTING_OVERLOADS!>fun foo() {}<!> // and here too
fun foo() {} // and here <!CONFLICTING_OVERLOADS!>fun foo() {}<!> // and here
fun foo() {} // and here <!CONFLICTING_OVERLOADS!>fun foo() {}<!> // and here
fun foo() {} // and here <!CONFLICTING_OVERLOADS!>fun foo() {}<!> // and here
fun bar() {} // and here <!CONFLICTING_OVERLOADS!>fun bar() {}<!> // and here
fun bar() {} // and here <!CONFLICTING_OVERLOADS!>fun bar() {}<!> // and here
fun bar() {} // and here <!CONFLICTING_OVERLOADS!>fun bar() {}<!> // and here
} }
@@ -1,4 +1,4 @@
// JET-11 Redeclaration & Forward reference for classes cause an exception // JET-11 Redeclaration & Forward reference for classes cause an exception
open class NoC <!REDECLARATION!>open class NoC<!>
class NoC1 : NoC() class NoC1 : NoC()
open class NoC <!REDECLARATION!>open class NoC<!>
@@ -3,32 +3,32 @@ package c
fun z(view: () -> Unit) {} fun z(view: () -> Unit) {}
fun x() = z { z { z { z { z { z { z { z { } } } } } } } } <!CONFLICTING_OVERLOADS!>fun x() = z { z { z { z { z { z { z { z { } } } } } } } }<!>
fun x() = z { z { z { z { z { z { z { z { } } } } } } } } <!CONFLICTING_OVERLOADS!>fun x() = z { z { z { z { z { z { z { z { } } } } } } } }<!>
fun x() = z { z { z { z { z { z { z { z { } } } } } } } } <!CONFLICTING_OVERLOADS!>fun x() = z { z { z { z { z { z { z { z { } } } } } } } }<!>
fun x() = z { z { z { z { z { z { z { z { } } } } } } } } <!CONFLICTING_OVERLOADS!>fun x() = z { z { z { z { z { z { z { z { } } } } } } } }<!>
fun x() = z { z { z { z { z { z { z { z { } } } } } } } } <!CONFLICTING_OVERLOADS!>fun x() = z { z { z { z { z { z { z { z { } } } } } } } }<!>
fun x() = z { z { z { z { z { z { z { z { } } } } } } } } <!CONFLICTING_OVERLOADS!>fun x() = z { z { z { z { z { z { z { z { } } } } } } } }<!>
fun x() = z { z { z { z { z { z { z { z { } } } } } } } } <!CONFLICTING_OVERLOADS!>fun x() = z { z { z { z { z { z { z { z { } } } } } } } }<!>
fun x() = z { z { z { z { z { z { z { z { } } } } } } } } <!CONFLICTING_OVERLOADS!>fun x() = z { z { z { z { z { z { z { z { } } } } } } } }<!>
fun x() = z { z { z { z { z { z { z { z { } } } } } } } } <!CONFLICTING_OVERLOADS!>fun x() = z { z { z { z { z { z { z { z { } } } } } } } }<!>
fun x() = z { z { z { z { z { z { z { z { } } } } } } } } <!CONFLICTING_OVERLOADS!>fun x() = z { z { z { z { z { z { z { z { } } } } } } } }<!>
fun x() = z { z { z { z { z { z { z { z { } } } } } } } } <!CONFLICTING_OVERLOADS!>fun x() = z { z { z { z { z { z { z { z { } } } } } } } }<!>
fun x() = z { z { z { z { z { z { z { z { } } } } } } } } <!CONFLICTING_OVERLOADS!>fun x() = z { z { z { z { z { z { z { z { } } } } } } } }<!>
fun x() = z { z { z { z { z { z { z { z { } } } } } } } } <!CONFLICTING_OVERLOADS!>fun x() = z { z { z { z { z { z { z { z { } } } } } } } }<!>
fun x() = z { z { z { z { z { z { z { z { } } } } } } } } <!CONFLICTING_OVERLOADS!>fun x() = z { z { z { z { z { z { z { z { } } } } } } } }<!>
fun x() = z { z { z { z { z { z { z { z { } } } } } } } } <!CONFLICTING_OVERLOADS!>fun x() = z { z { z { z { z { z { z { z { } } } } } } } }<!>
fun x() = z { z { z { z { z { z { z { z { } } } } } } } } <!CONFLICTING_OVERLOADS!>fun x() = z { z { z { z { z { z { z { z { } } } } } } } }<!>
fun x() = z { z { z { z { z { z { z { z { } } } } } } } } <!CONFLICTING_OVERLOADS!>fun x() = z { z { z { z { z { z { z { z { } } } } } } } }<!>
fun x() = z { z { z { z { z { z { z { z { } } } } } } } } <!CONFLICTING_OVERLOADS!>fun x() = z { z { z { z { z { z { z { z { } } } } } } } }<!>
fun x() = z { z { z { z { z { z { z { z { } } } } } } } } <!CONFLICTING_OVERLOADS!>fun x() = z { z { z { z { z { z { z { z { } } } } } } } }<!>
fun x() = z { z { z { z { z { z { z { z { } } } } } } } } <!CONFLICTING_OVERLOADS!>fun x() = z { z { z { z { z { z { z { z { } } } } } } } }<!>
fun x() = z { z { z { z { z { z { z { z { } } } } } } } } <!CONFLICTING_OVERLOADS!>fun x() = z { z { z { z { z { z { z { z { } } } } } } } }<!>
fun x() = z { z { z { z { z { z { z { z { } } } } } } } } <!CONFLICTING_OVERLOADS!>fun x() = z { z { z { z { z { z { z { z { } } } } } } } }<!>
fun x() = z { z { z { z { z { z { z { z { } } } } } } } } <!CONFLICTING_OVERLOADS!>fun x() = z { z { z { z { z { z { z { z { } } } } } } } }<!>
fun x() = z { z { z { z { z { z { z { z { } } } } } } } } <!CONFLICTING_OVERLOADS!>fun x() = z { z { z { z { z { z { z { z { } } } } } } } }<!>
fun x() = z { z { z { z { z { z { z { z { } } } } } } } } <!CONFLICTING_OVERLOADS!>fun x() = z { z { z { z { z { z { z { z { } } } } } } } }<!>
fun x() = z { z { z { z { z { z { z { z { } } } } } } } } <!CONFLICTING_OVERLOADS!>fun x() = z { z { z { z { z { z { z { z { } } } } } } } }<!>
fun x() = z { z { z { z { z { z { z { z { } } } } } } } } <!CONFLICTING_OVERLOADS!>fun x() = z { z { z { z { z { z { z { z { } } } } } } } }<!>
class x() {} class x() {}
@@ -1,7 +1,7 @@
class A <!REDECLARATION!>class A<!>
class A { <!REDECLARATION!>class A {
constructor() constructor()
} }<!>
class B class B
class Outer { class Outer {
@@ -1,15 +1,15 @@
// FILE: main.kt // FILE: main.kt
interface A { interface A {
suspend fun foo() <!CONFLICTING_OVERLOADS!>suspend fun foo()<!>
fun foo() <!CONFLICTING_OVERLOADS!>fun foo()<!>
} }
interface B : A { interface B : A {
suspend override fun foo() { <!CONFLICTING_OVERLOADS!>suspend override fun foo() {
} }<!>
override fun foo() { <!CONFLICTING_OVERLOADS!>override fun foo() {
} }<!>
} }
@@ -1,13 +1,13 @@
//!DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE //!DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
// !WITH_NEW_INFERENCE // !WITH_NEW_INFERENCE
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") <!CONFLICTING_OVERLOADS!>@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@kotlin.jvm.JvmName("containsAny") @kotlin.jvm.JvmName("containsAny")
<!HIDDEN!>@kotlin.internal.LowPriorityInOverloadResolution<!> <!HIDDEN!>@kotlin.internal.LowPriorityInOverloadResolution<!>
public fun <T> Iterable<T>.contains1(element: T): Int = null!! public fun <T> Iterable<T>.contains1(element: T): Int = null!!<!>
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") <!CONFLICTING_OVERLOADS!>@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
public fun <T> Iterable<T>.contains1(element: @kotlin.internal.NoInfer T): Boolean = null!! public fun <T> Iterable<T>.contains1(element: @kotlin.internal.NoInfer T): Boolean = null!!<!>
fun test() { fun test() {
@@ -2,13 +2,13 @@
// !WITH_NEW_INFERENCE // !WITH_NEW_INFERENCE
// !LANGUAGE: -NonStrictOnlyInputTypesChecks // !LANGUAGE: -NonStrictOnlyInputTypesChecks
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") <!CONFLICTING_OVERLOADS!>@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@kotlin.jvm.JvmName("containsAny") @kotlin.jvm.JvmName("containsAny")
<!HIDDEN!>@kotlin.internal.LowPriorityInOverloadResolution<!> <!HIDDEN!>@kotlin.internal.LowPriorityInOverloadResolution<!>
public fun <T> Iterable<T>.contains1(element: T): Int = null!! public fun <T> Iterable<T>.contains1(element: T): Int = null!!<!>
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") <!CONFLICTING_OVERLOADS!>@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
public fun <<!HIDDEN!>@kotlin.internal.OnlyInputTypes<!> T> Iterable<T>.contains1(element: T): Boolean = null!! public fun <<!HIDDEN!>@kotlin.internal.OnlyInputTypes<!> T> Iterable<T>.contains1(element: T): Boolean = null!!<!>
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@JvmName("getAny") @JvmName("getAny")
@@ -54,9 +54,9 @@ class Case2() {
* TESTCASE NUMBER: 3 * TESTCASE NUMBER: 3
* NOTE: check abstract member cannot be accessed directly * NOTE: check abstract member cannot be accessed directly
*/ */
class Case3(override val boo: String) : BaseCase3() { class Case3(<!REDECLARATION!>override val boo: String<!>) : BaseCase3() {
override val zoo: String = super.<!ABSTRACT_SUPER_CALL!>foo<!>() override val zoo: String = super.<!ABSTRACT_SUPER_CALL!>foo<!>()
override val boo: String = super.<!ABSTRACT_SUPER_CALL!>boo<!> <!REDECLARATION!>override val boo: String = super.<!ABSTRACT_SUPER_CALL!>boo<!><!>
override val value: String = super.<!ABSTRACT_SUPER_CALL!>zoo<!> override val value: String = super.<!ABSTRACT_SUPER_CALL!>zoo<!>
val hoo: String = super.<!ABSTRACT_SUPER_CALL!>zoo<!> val hoo: String = super.<!ABSTRACT_SUPER_CALL!>zoo<!>
@@ -18,7 +18,7 @@ class Case2() {
fun foo(vararg x: Int?): Unit = TODO() // (1.2) fun foo(vararg x: Int?): Unit = TODO() // (1.2)
fun case(){ fun case(){
foo(1, 1) <!AMBIGUITY!>foo<!>(1, 1)
} }
} }
// TESTCASE NUMBER: 3 // TESTCASE NUMBER: 3
@@ -27,7 +27,7 @@ class Case3() {
fun foo(vararg x: Int?): Unit = TODO() // (1.2) fun foo(vararg x: Int?): Unit = TODO() // (1.2)
fun case(){ fun case(){
foo(1, 1) <!AMBIGUITY!>foo<!>(1, 1)
} }
} }
@@ -5,7 +5,7 @@
// TESTCASE NUMBER: 1 // TESTCASE NUMBER: 1
fun case_1(vararg x: Int?) { fun case_1(vararg x: Int?) {
if (x != null) { if (x != null) {
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.IntArray & kotlin.IntArray")!>x<!> <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Array<out kotlin.Int?> & kotlin.Array<out kotlin.Int?>")!>x<!>
x[0] x[0]
} }
} }
@@ -21,8 +21,8 @@ fun case_2(vararg x: Int?) {
x[0].also { x[0].also {
if (it != null) { if (it != null) {
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int & kotlin.Int")!>it<!> <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int & kotlin.Int?")!>it<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int & kotlin.Int")!>it<!>.inv() <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int & kotlin.Int?")!>it<!>.inv()
} }
} }
} }