diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java index 5ffb96e6c83..c1829d5128a 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java @@ -313,8 +313,6 @@ public class JetFlowInformationProvider { hasBackingField = trace.get(BindingContext.BACKING_FIELD_REQUIRED, (PropertyDescriptor) variableDescriptor); } if ((isInitializedNotHere || !hasBackingField) && !variableDescriptor.isVar() && !varWithValReassignErrorGenerated.contains(variableDescriptor)) { - varWithValReassignErrorGenerated.add(variableDescriptor); - boolean hasReassignMethodReturningUnit = false; JetSimpleNameExpression operationReference = null; PsiElement parent = expression.getParent(); @@ -343,6 +341,7 @@ public class JetFlowInformationProvider { } } if (!hasReassignMethodReturningUnit) { + varWithValReassignErrorGenerated.add(variableDescriptor); trace.report(Errors.VAL_REASSIGNMENT.on(expression, variableDescriptor)); return true; } diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1571.jet b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1571.jet new file mode 100644 index 00000000000..98702fa1591 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/kt1571.jet @@ -0,0 +1,42 @@ +//KT-1571 Frontend fails to check val reassigment for operator overloading. +package kt1571 + +var c0 = 0 +var c1 = 0 +var c2 = 0 + +class A() { + var p = 0 + fun divAssign(a : Int) { + c1++; + } + fun times(a : Int) : A { + c2++; + return this; + } +} + +val a : A = A() +get() { + c0++ + return $a +} + +fun box() : String { + + a /= 3 + if (c0 != 1) { + return "1" + } + if (c1 != 1) { + return "2" + } + a *= 3 // a = a * 3, shouldn't be able to do this on val + if (c0 != 2) { + return "3" + } + if (c2 != 1) { + return "4" + } + return "OK" +}