[FE 1.0] Fix reporting of uninitialized parameter in default values of parameters
^KT-25694 ^KT-50723 Fixed
This commit is contained in:
committed by
teamcity
parent
92e893bebe
commit
ecc890efe8
+72
@@ -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
|
||||
) {}
|
||||
Vendored
+72
@@ -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
|
||||
) {}
|
||||
compiler/testData/diagnostics/tests/controlFlowAnalysis/accessValueParameterInDefaultValue_after.txt
Vendored
+18
@@ -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
|
||||
}
|
||||
+72
@@ -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
|
||||
) {}
|
||||
compiler/testData/diagnostics/tests/controlFlowAnalysis/accessValueParameterInDefaultValue_before.kt
Vendored
+72
@@ -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
|
||||
) {}
|
||||
+19
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user