[FE 1.0] Fix reporting of uninitialized parameter in default values of parameters

^KT-25694
^KT-50723 Fixed
This commit is contained in:
Dmitriy Novozhilov
2022-01-11 15:39:07 +03:00
committed by teamcity
parent 92e893bebe
commit ecc890efe8
16 changed files with 459 additions and 4 deletions
@@ -0,0 +1,72 @@
// LANGUAGE: +ProhibitIllegalValueParameterUsageInDefaultArguments
// DIAGNOSTICS: -UNUSED_PARAMETER
// WITH_STDLIB
// ISSUE: KT-25694
fun test_1(
x: () -> String = { <!UNINITIALIZED_PARAMETER!>y<!> }, // Error
y: String = "OK"
) {}
fun test_2(
x: String = "OK",
y: () -> String = { x } // OK
) {}
fun test_3(
x: () -> Any = { y() to <!UNINITIALIZED_PARAMETER!>y<!>.invoke() }, // Error
y: () -> String = { "OK" }
) {}
fun test_4(
x: () -> String = { "OK" },
y: () -> Any = { x() to x.invoke() } // OK
) {}
interface Foo {
fun foo()
}
fun test_5(
x: Foo = object : Foo {
val z1 = <!UNINITIALIZED_PARAMETER!>y<!> // Error
val z2 = run { <!UNINITIALIZED_PARAMETER!>y<!> } // Error
init {
println(<!UNINITIALIZED_PARAMETER!>y<!>) // Error
}
override fun foo() {
println(<!UNINITIALIZED_PARAMETER!>y<!>) // Error
}
},
y: String = "OK"
) {}
fun test_6(
x: String = "OK",
y: Foo = object : Foo {
val z1 = x // OK
val z2 = run { x } // OK
init {
println(x) // OK
}
override fun foo() {
println(x) // OK
}
}
) {}
fun getFoo(x: String): Foo = null!!
fun test_7(
x: Foo = object : Foo by getFoo(<!UNINITIALIZED_PARAMETER!>y<!>) {}, // Error
y: String = "OK"
) {}
fun test_8(
x: String = "OK",
y: Foo = object : Foo by getFoo(x) {} // OK
) {}
@@ -0,0 +1,72 @@
// LANGUAGE: +ProhibitIllegalValueParameterUsageInDefaultArguments
// DIAGNOSTICS: -UNUSED_PARAMETER
// WITH_STDLIB
// ISSUE: KT-25694
fun test_1(
x: () -> String = { <!UNINITIALIZED_PARAMETER!>y<!> }, // Error
y: String = "OK"
) {}
fun test_2(
x: String = "OK",
y: () -> String = { x } // OK
) {}
fun test_3(
x: () -> Any = { <!UNINITIALIZED_PARAMETER!>y<!>() to <!UNINITIALIZED_PARAMETER!>y<!>.invoke() }, // Error
y: () -> String = { "OK" }
) {}
fun test_4(
x: () -> String = { "OK" },
y: () -> Any = { x() to x.invoke() } // OK
) {}
interface Foo {
fun foo()
}
fun test_5(
x: Foo = object : Foo {
val z1 = <!UNINITIALIZED_PARAMETER, UNINITIALIZED_PARAMETER!>y<!> // Error
val z2 = run { <!UNINITIALIZED_PARAMETER!>y<!> } // Error
init {
println(<!UNINITIALIZED_PARAMETER!>y<!>) // Error
}
override fun foo() {
println(<!UNINITIALIZED_PARAMETER!>y<!>) // Error
}
},
y: String = "OK"
) {}
fun test_6(
x: String = "OK",
y: Foo = object : Foo {
val z1 = x // OK
val z2 = run { x } // OK
init {
println(x) // OK
}
override fun foo() {
println(x) // OK
}
}
) {}
fun getFoo(x: String): Foo = null!!
fun test_7(
x: Foo = object : Foo by getFoo(<!UNINITIALIZED_PARAMETER, UNINITIALIZED_PARAMETER!>y<!>) {}, // Error
y: String = "OK"
) {}
fun test_8(
x: String = "OK",
y: Foo = object : Foo by getFoo(x) {} // OK
) {}
@@ -0,0 +1,18 @@
package
public fun getFoo(/*0*/ x: kotlin.String): Foo
public fun test_1(/*0*/ x: () -> kotlin.String = ..., /*1*/ y: kotlin.String = ...): kotlin.Unit
public fun test_2(/*0*/ x: kotlin.String = ..., /*1*/ y: () -> kotlin.String = ...): kotlin.Unit
public fun test_3(/*0*/ x: () -> kotlin.Any = ..., /*1*/ y: () -> kotlin.String = ...): kotlin.Unit
public fun test_4(/*0*/ x: () -> kotlin.String = ..., /*1*/ y: () -> kotlin.Any = ...): kotlin.Unit
public fun test_5(/*0*/ x: Foo = ..., /*1*/ y: kotlin.String = ...): kotlin.Unit
public fun test_6(/*0*/ x: kotlin.String = ..., /*1*/ y: Foo = ...): kotlin.Unit
public fun test_7(/*0*/ x: Foo = ..., /*1*/ y: kotlin.String = ...): kotlin.Unit
public fun test_8(/*0*/ x: kotlin.String = ..., /*1*/ y: Foo = ...): kotlin.Unit
public interface Foo {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public abstract fun foo(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,72 @@
// LANGUAGE: -ProhibitIllegalValueParameterUsageInDefaultArguments
// DIAGNOSTICS: -UNUSED_PARAMETER
// WITH_STDLIB
// ISSUE: KT-25694
fun test_1(
x: () -> String = { <!UNINITIALIZED_PARAMETER!>y<!> }, // Error
y: String = "OK"
) {}
fun test_2(
x: String = "OK",
y: () -> String = { x } // OK
) {}
fun test_3(
x: () -> Any = { y() to <!UNINITIALIZED_PARAMETER!>y<!>.invoke() }, // Error
y: () -> String = { "OK" }
) {}
fun test_4(
x: () -> String = { "OK" },
y: () -> Any = { x() to x.invoke() } // OK
) {}
interface Foo {
fun foo()
}
fun test_5(
x: Foo = object : Foo {
val z1 = <!UNINITIALIZED_PARAMETER!>y<!> // Error
val z2 = run { <!UNINITIALIZED_PARAMETER!>y<!> } // Error
init {
println(<!UNINITIALIZED_PARAMETER!>y<!>) // Error
}
override fun foo() {
println(<!UNINITIALIZED_PARAMETER!>y<!>) // Error
}
},
y: String = "OK"
) {}
fun test_6(
x: String = "OK",
y: Foo = object : Foo {
val z1 = x // OK
val z2 = run { x } // OK
init {
println(x) // OK
}
override fun foo() {
println(x) // OK
}
}
) {}
fun getFoo(x: String): Foo = null!!
fun test_7(
x: Foo = object : Foo by getFoo(<!UNINITIALIZED_PARAMETER!>y<!>) {}, // Error
y: String = "OK"
) {}
fun test_8(
x: String = "OK",
y: Foo = object : Foo by getFoo(x) {} // OK
) {}
@@ -0,0 +1,72 @@
// LANGUAGE: -ProhibitIllegalValueParameterUsageInDefaultArguments
// DIAGNOSTICS: -UNUSED_PARAMETER
// WITH_STDLIB
// ISSUE: KT-25694
fun test_1(
x: () -> String = { <!UNINITIALIZED_PARAMETER_WARNING!>y<!> }, // Error
y: String = "OK"
) {}
fun test_2(
x: String = "OK",
y: () -> String = { x } // OK
) {}
fun test_3(
x: () -> Any = { <!UNINITIALIZED_PARAMETER_WARNING!>y<!>() to <!UNINITIALIZED_PARAMETER_WARNING!>y<!>.invoke() }, // Error
y: () -> String = { "OK" }
) {}
fun test_4(
x: () -> String = { "OK" },
y: () -> Any = { x() to x.invoke() } // OK
) {}
interface Foo {
fun foo()
}
fun test_5(
x: Foo = object : Foo {
val z1 = <!UNINITIALIZED_PARAMETER, UNINITIALIZED_PARAMETER_WARNING!>y<!> // Error
val z2 = run { <!UNINITIALIZED_PARAMETER_WARNING!>y<!> } // Error
init {
println(<!UNINITIALIZED_PARAMETER_WARNING!>y<!>) // Error
}
override fun foo() {
println(<!UNINITIALIZED_PARAMETER_WARNING!>y<!>) // Error
}
},
y: String = "OK"
) {}
fun test_6(
x: String = "OK",
y: Foo = object : Foo {
val z1 = x // OK
val z2 = run { x } // OK
init {
println(x) // OK
}
override fun foo() {
println(x) // OK
}
}
) {}
fun getFoo(x: String): Foo = null!!
fun test_7(
x: Foo = object : Foo by getFoo(<!UNINITIALIZED_PARAMETER, UNINITIALIZED_PARAMETER_WARNING!>y<!>) {}, // Error
y: String = "OK"
) {}
fun test_8(
x: String = "OK",
y: Foo = object : Foo by getFoo(x) {} // OK
) {}
@@ -0,0 +1,19 @@
package
public fun getFoo(/*0*/ x: kotlin.String): Foo
public fun test_1(/*0*/ x: () -> kotlin.String = ..., /*1*/ y: kotlin.String = ...): kotlin.Unit
public fun test_2(/*0*/ x: kotlin.String = ..., /*1*/ y: () -> kotlin.String = ...): kotlin.Unit
public fun test_3(/*0*/ x: () -> kotlin.Any = ..., /*1*/ y: () -> kotlin.String = ...): kotlin.Unit
public fun test_4(/*0*/ x: () -> kotlin.String = ..., /*1*/ y: () -> kotlin.Any = ...): kotlin.Unit
public fun test_5(/*0*/ x: Foo = ..., /*1*/ y: kotlin.String = ...): kotlin.Unit
public fun test_6(/*0*/ x: kotlin.String = ..., /*1*/ y: Foo = ...): kotlin.Unit
public fun test_7(/*0*/ x: Foo = ..., /*1*/ y: kotlin.String = ...): kotlin.Unit
public fun test_8(/*0*/ x: kotlin.String = ..., /*1*/ y: Foo = ...): kotlin.Unit
public interface Foo {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public abstract fun foo(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}