diff --git a/compiler/testData/codegen/box/smartCasts/NullableFunctionTypeAsMemberImmutableProperty.kt b/compiler/testData/codegen/box/smartCasts/NullableFunctionTypeAsMemberImmutableProperty.kt new file mode 100644 index 00000000000..e0a7fe50732 --- /dev/null +++ b/compiler/testData/codegen/box/smartCasts/NullableFunctionTypeAsMemberImmutableProperty.kt @@ -0,0 +1,29 @@ +// IGNORE_BACKEND_K1: ANY +// ISSUE: KT-63705 + +fun box(): String { + KlassA({}) + KlassB() + return "OK" +} + +class KlassA(arg: (() -> Unit)?) { + val func: (() -> Unit)? = arg + init { + if (func != null) { + func() + } + } +} + +class KlassB { + val func: (() -> Unit)? + init { + if (true) { + func = {} + func() + } else { + func = null + } + } +} diff --git a/compiler/testData/codegen/box/smartCasts/NullableFunctionTypeAsMemberImmutablePropertyFromConstructor.kt b/compiler/testData/codegen/box/smartCasts/NullableFunctionTypeAsMemberImmutablePropertyFromConstructor.kt new file mode 100644 index 00000000000..8a0dea73bcb --- /dev/null +++ b/compiler/testData/codegen/box/smartCasts/NullableFunctionTypeAsMemberImmutablePropertyFromConstructor.kt @@ -0,0 +1,15 @@ +// IGNORE_BACKEND_K1: ANY +// ISSUE: KT-63705 + +fun box(): String { + Klass({}) + return "OK" +} + +class Klass(val func: (() -> Unit)?) { + init { + if (func != null) { + func() + } + } +} diff --git a/compiler/testData/codegen/box/smartCasts/NullableFunctionTypeAsPrimaryConstructorParameter.kt b/compiler/testData/codegen/box/smartCasts/NullableFunctionTypeAsPrimaryConstructorParameter.kt new file mode 100644 index 00000000000..366f5c078e4 --- /dev/null +++ b/compiler/testData/codegen/box/smartCasts/NullableFunctionTypeAsPrimaryConstructorParameter.kt @@ -0,0 +1,12 @@ +fun box(): String { + Klass({}) + return "OK" +} + +class Klass(func: (() -> Unit)?) { + init { + if (func != null) { + func() + } + } +} diff --git a/compiler/testData/codegen/box/smartCasts/NullableFunctionTypeAsSecondaryConstructorParameter.kt b/compiler/testData/codegen/box/smartCasts/NullableFunctionTypeAsSecondaryConstructorParameter.kt new file mode 100644 index 00000000000..2581b812d16 --- /dev/null +++ b/compiler/testData/codegen/box/smartCasts/NullableFunctionTypeAsSecondaryConstructorParameter.kt @@ -0,0 +1,12 @@ +fun box(): String { + Klass({}) + return "OK" +} + +class Klass { + constructor(func: (() -> Unit)?) { + if (func != null) { + func() + } + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/NullableFunctionTypeAsMemberMutableProperty.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/NullableFunctionTypeAsMemberMutableProperty.fir.kt new file mode 100644 index 00000000000..9f7d886550e --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/NullableFunctionTypeAsMemberMutableProperty.fir.kt @@ -0,0 +1,26 @@ +fun box(): String { + KlassA({}) + KlassB() + return "OK" +} + +class KlassA(arg: (() -> Unit)?) { + var func: (() -> Unit)? = arg + init { + if (func != null) { + func() + } + } +} + +class KlassB { + var func: (() -> Unit)? + init { + if (true) { + func = {} + func() + } else { + func = null + } + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/NullableFunctionTypeAsMemberMutableProperty.kt b/compiler/testData/diagnostics/tests/smartCasts/NullableFunctionTypeAsMemberMutableProperty.kt new file mode 100644 index 00000000000..fcde810067a --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/NullableFunctionTypeAsMemberMutableProperty.kt @@ -0,0 +1,26 @@ +fun box(): String { + KlassA({}) + KlassB() + return "OK" +} + +class KlassA(arg: (() -> Unit)?) { + var func: (() -> Unit)? = arg + init { + if (func != null) { + func() + } + } +} + +class KlassB { + var func: (() -> Unit)? + init { + if (true) { + func = {} + func() + } else { + func = null + } + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/NullableFunctionTypeAsMemberMutablePropertyFromConstructor.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/NullableFunctionTypeAsMemberMutablePropertyFromConstructor.fir.kt new file mode 100644 index 00000000000..6410483128c --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/NullableFunctionTypeAsMemberMutablePropertyFromConstructor.fir.kt @@ -0,0 +1,12 @@ +fun box(): String { + Klass({}) + return "OK" +} + +class Klass(var func: (() -> Unit)?) { + init { + if (func != null) { + func() + } + } +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/NullableFunctionTypeAsMemberMutablePropertyFromConstructor.kt b/compiler/testData/diagnostics/tests/smartCasts/NullableFunctionTypeAsMemberMutablePropertyFromConstructor.kt new file mode 100644 index 00000000000..5fe2fcb4d65 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/NullableFunctionTypeAsMemberMutablePropertyFromConstructor.kt @@ -0,0 +1,12 @@ +fun box(): String { + Klass({}) + return "OK" +} + +class Klass(var func: (() -> Unit)?) { + init { + if (func != null) { + func() + } + } +}