[FIR] Report PROPERTY_WITH_NO_TYPE_NO_INITIALIZER for all properties

Currently, PROPERTY_WITH_NO_TYPE_NO_INITIALIZER is reported for local
variables, but not reported for member or top-level properties. Add a
check to the common `checkPropertyInitializer` for when a property
type cannot be determined from the getter.

This also corrects a K1 versus K2 inconsistency, where K2 would allow
blocks from getters to determine property type instead of only allowing
expression bodies.

^KT-59935 Fixed
^KT-60117 Fixed
^KT-60123 Fixed
This commit is contained in:
Brian Norman
2023-10-23 14:32:26 -05:00
committed by Space Team
parent b154283149
commit 01a757cbd6
16 changed files with 52 additions and 31 deletions
@@ -1,9 +1,9 @@
BEFORE MODIFICATION:
public final [ResolvedTo(BODY_RESOLVE)] val x: R|kotlin/Int|
public [ResolvedTo(BODY_RESOLVE)] [ContainingClassKey=A] get(): R|kotlin/Int| {
public final [ResolvedTo(BODY_RESOLVE)] val x: <ERROR TYPE REF: Cannot infer variable type without initializer / getter / delegate>
public [ResolvedTo(BODY_RESOLVE)] [ContainingClassKey=A] get(): <ERROR TYPE REF: Cannot infer variable type without initializer / getter / delegate> {
^ R|/doSmth|(String(str))
}
AFTER MODIFICATION:
public final [ResolvedTo(ANNOTATION_ARGUMENTS)] val x: R|kotlin/Int|
public [ResolvedTo(ANNOTATION_ARGUMENTS)] [ContainingClassKey=A] get(): R|kotlin/Int| { LAZY_BLOCK }
public final [ResolvedTo(ANNOTATION_ARGUMENTS)] val x: <ERROR TYPE REF: Cannot infer variable type without initializer / getter / delegate>
public [ResolvedTo(ANNOTATION_ARGUMENTS)] [ContainingClassKey=A] get(): <ERROR TYPE REF: Cannot infer variable type without initializer / getter / delegate> { LAZY_BLOCK }
@@ -1,9 +1,9 @@
BEFORE MODIFICATION:
public final [ResolvedTo(BODY_RESOLVE)] val x: R|kotlin/Int|
public [ResolvedTo(BODY_RESOLVE)] [ContainingClassKey=A] get(): R|kotlin/Int| {
public final [ResolvedTo(BODY_RESOLVE)] val x: <ERROR TYPE REF: Cannot infer variable type without initializer / getter / delegate>
public [ResolvedTo(BODY_RESOLVE)] [ContainingClassKey=A] get(): <ERROR TYPE REF: Cannot infer variable type without initializer / getter / delegate> {
^ R|/doSmth|(String(str))
}
AFTER MODIFICATION:
public final [ResolvedTo(ANNOTATION_ARGUMENTS)] val x: R|kotlin/Int|
public [ResolvedTo(ANNOTATION_ARGUMENTS)] [ContainingClassKey=A] get(): R|kotlin/Int| { LAZY_BLOCK }
public final [ResolvedTo(ANNOTATION_ARGUMENTS)] val x: <ERROR TYPE REF: Cannot infer variable type without initializer / getter / delegate>
public [ResolvedTo(ANNOTATION_ARGUMENTS)] [ContainingClassKey=A] get(): <ERROR TYPE REF: Cannot infer variable type without initializer / getter / delegate> { LAZY_BLOCK }
@@ -1,9 +1,9 @@
BEFORE MODIFICATION:
public final [ResolvedTo(BODY_RESOLVE)] val x: R|kotlin/Int|
public [ResolvedTo(BODY_RESOLVE)] get(): R|kotlin/Int| {
public final [ResolvedTo(BODY_RESOLVE)] val x: <ERROR TYPE REF: Cannot infer variable type without initializer / getter / delegate>
public [ResolvedTo(BODY_RESOLVE)] get(): <ERROR TYPE REF: Cannot infer variable type without initializer / getter / delegate> {
^ R|/doSmth|(String(str))
}
AFTER MODIFICATION:
public final [ResolvedTo(ANNOTATION_ARGUMENTS)] val x: R|kotlin/Int|
public [ResolvedTo(ANNOTATION_ARGUMENTS)] get(): R|kotlin/Int| { LAZY_BLOCK }
public final [ResolvedTo(ANNOTATION_ARGUMENTS)] val x: <ERROR TYPE REF: Cannot infer variable type without initializer / getter / delegate>
public [ResolvedTo(ANNOTATION_ARGUMENTS)] get(): <ERROR TYPE REF: Cannot infer variable type without initializer / getter / delegate> { LAZY_BLOCK }
@@ -1,9 +1,9 @@
BEFORE MODIFICATION:
public final [ResolvedTo(BODY_RESOLVE)] val x: R|kotlin/Int|
public [ResolvedTo(BODY_RESOLVE)] get(): R|kotlin/Int| {
public final [ResolvedTo(BODY_RESOLVE)] val x: <ERROR TYPE REF: Cannot infer variable type without initializer / getter / delegate>
public [ResolvedTo(BODY_RESOLVE)] get(): <ERROR TYPE REF: Cannot infer variable type without initializer / getter / delegate> {
^ R|/doSmth|(String(str))
}
AFTER MODIFICATION:
public final [ResolvedTo(ANNOTATION_ARGUMENTS)] val x: R|kotlin/Int|
public [ResolvedTo(ANNOTATION_ARGUMENTS)] get(): R|kotlin/Int| { LAZY_BLOCK }
public final [ResolvedTo(ANNOTATION_ARGUMENTS)] val x: <ERROR TYPE REF: Cannot infer variable type without initializer / getter / delegate>
public [ResolvedTo(ANNOTATION_ARGUMENTS)] get(): <ERROR TYPE REF: Cannot infer variable type without initializer / getter / delegate> { LAZY_BLOCK }