Introduce special CAPTURED_VAL_INITIALIZATION for members
This commit is contained in:
@@ -459,7 +459,12 @@ class ControlFlowInformationProvider private constructor(
|
||||
if (!hasReassignMethodReturningUnit) {
|
||||
if (!isThisOrNoDispatchReceiver || !varWithValReassignErrorGenerated.contains(variableDescriptor)) {
|
||||
if (captured && !mayBeInitializedNotHere && hasBackingField && isThisOrNoDispatchReceiver) {
|
||||
report(Errors.CAPTURED_VAL_INITIALIZATION.on(expression, variableDescriptor), ctxt)
|
||||
if (variableDescriptor.containingDeclaration is ClassDescriptor) {
|
||||
report(Errors.CAPTURED_MEMBER_VAL_INITIALIZATION.on(expression, variableDescriptor), ctxt)
|
||||
}
|
||||
else {
|
||||
report(Errors.CAPTURED_VAL_INITIALIZATION.on(expression, variableDescriptor), ctxt)
|
||||
}
|
||||
}
|
||||
else {
|
||||
report(Errors.VAL_REASSIGNMENT.on(expression, variableDescriptor), ctxt)
|
||||
|
||||
@@ -762,6 +762,7 @@ public interface Errors {
|
||||
|
||||
DiagnosticFactory1<KtExpression, DeclarationDescriptor> VAL_REASSIGNMENT = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<KtExpression, DeclarationDescriptor> CAPTURED_VAL_INITIALIZATION = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<KtExpression, DeclarationDescriptor> CAPTURED_MEMBER_VAL_INITIALIZATION = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<KtExpression, DeclarationDescriptor> SETTER_PROJECTED_OUT = DiagnosticFactory1.create(ERROR);
|
||||
|
||||
DiagnosticFactory1<KtExpression, DeclarationDescriptor> INITIALIZATION_BEFORE_DECLARATION = DiagnosticFactory1.create(ERROR);
|
||||
|
||||
+1
@@ -300,6 +300,7 @@ public class DefaultErrorMessages {
|
||||
|
||||
MAP.put(VAL_REASSIGNMENT, "Val cannot be reassigned", NAME);
|
||||
MAP.put(CAPTURED_VAL_INITIALIZATION, "Captured values initialization is forbidden due to possible reassignment", NAME);
|
||||
MAP.put(CAPTURED_MEMBER_VAL_INITIALIZATION, "Captured member values initialization is forbidden due to possible reassignment", NAME);
|
||||
MAP.put(SETTER_PROJECTED_OUT, "Setter for ''{0}'' is removed by type projection", NAME);
|
||||
MAP.put(INVISIBLE_SETTER, "Cannot assign to ''{0}'': the setter is {1} in {2}", NAME, VISIBILITY, NAME_OF_PARENT_OR_FILE);
|
||||
MAP.put(INITIALIZATION_BEFORE_DECLARATION, "Variable cannot be initialized before declaration", NAME);
|
||||
|
||||
+2
-2
@@ -7,7 +7,7 @@ class Test {
|
||||
val t = object {
|
||||
fun some() {
|
||||
// See KT-13597
|
||||
<!CAPTURED_VAL_INITIALIZATION!>a<!> = "12"
|
||||
<!CAPTURED_MEMBER_VAL_INITIALIZATION!>a<!> = "12"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ class Test4 {
|
||||
init {
|
||||
exec {
|
||||
// See KT-14381
|
||||
<!CAPTURED_VAL_INITIALIZATION!>a<!> = "12"
|
||||
<!CAPTURED_MEMBER_VAL_INITIALIZATION!>a<!> = "12"
|
||||
}
|
||||
a = "34"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user