Disabled highlighting for variables which are captured in inlined closure.

This commit is contained in:
Evgeny Gerashchenko
2013-04-10 15:41:04 +04:00
parent 6285e5a9f4
commit d502d45772
8 changed files with 188 additions and 13 deletions
@@ -24,6 +24,7 @@ import org.jetbrains.jet.lang.descriptors.impl.LocalVariableDescriptor;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.expressions.CaptureKind;
import org.jetbrains.jet.renderer.DescriptorRenderer;
import static org.jetbrains.jet.lang.resolve.BindingContext.*;
@@ -88,7 +89,7 @@ class VariablesHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
JetPsiChecker.highlightName(holder, elementToHighlight, JetHighlightingColors.MUTABLE_VARIABLE);
}
if (Boolean.TRUE.equals(bindingContext.get(CAPTURED_IN_CLOSURE, variableDescriptor))) {
if (bindingContext.get(CAPTURED_IN_CLOSURE, variableDescriptor) == CaptureKind.NOT_INLINE) {
String msg = ((VariableDescriptor) descriptor).isVar()
? "Wrapped into a reference object to be modified when captured in a closure"
: "Value captured in a closure";
@@ -0,0 +1,91 @@
<info>inline</info> fun <T> run(f: () -> T) = f()
fun run2(f: () -> Unit) = f()
fun inline() {
val x = 1
run { x }
val x1 = 1
run ({ x1 })
val x2 = 1
run (f = { x2 })
val x3 = 1
run {
run {
x3
}
}
}
fun notInline() {
val <info descr="Value captured in a closure">y2</info> = 1
run { <info descr="Value captured in a closure">y2</info> }
run2 { <info descr="Value captured in a closure">y2</info> }
val <info descr="Value captured in a closure">y3</info> = 1
run2 { <info descr="Value captured in a closure">y3</info> }
run { <info descr="Value captured in a closure">y3</info> }
// wrapped, using in not inline
val <info descr="Value captured in a closure">z</info> = 2
{ <info descr="Value captured in a closure">z</info> }()
val <info descr="Value captured in a closure">z1</info> = 3
run2 { <info descr="Value captured in a closure">z1</info> }
}
fun nestedDifferent() { // inline within non-inline and vice-versa
val <info descr="Value captured in a closure">y</info> = 1
{
run {
<info descr="Value captured in a closure">y</info>
}
}()
val <info descr="Value captured in a closure">y1</info> = 1
run {
{ <info descr="Value captured in a closure">y1</info> }()
}
}
fun localFunctionAndClass() {
val <info descr="Value captured in a closure">u</info> = 1
fun localFun() {
run {
<info descr="Value captured in a closure">u</info>
}
}
val <info descr="Value captured in a closure"><warning>v</warning></info> = 1 // erroneous "unused warning" is caused by KT-3501
class LocalClass {
fun f() {
run {
<info descr="Value captured in a closure">v</info>
}
}
}
}
fun objectExpression() {
val <info descr="Value captured in a closure">u1</info> = 1
object : Any() {
fun f() {
run {
<info descr="Value captured in a closure">u1</info>
}
}
}
val <info descr="Value captured in a closure">u2</info> = 1
object : Any() {
val <info>prop</info> = run {
<info descr="Value captured in a closure">u2</info>
}
}
val <info descr="Value captured in a closure">u3</info> = ""
object : Throwable(run { <info descr="Value captured in a closure">u3</info> }) {
}
}
@@ -417,6 +417,11 @@ public class JetPsiCheckerTestGenerated extends AbstractJetPsiCheckerTest {
doTestWithInfos("idea/testData/checker/infos/Autocasts.kt");
}
@TestMetadata("CapturedInInlinedClosure.kt")
public void testCapturedInInlinedClosure() throws Exception {
doTestWithInfos("idea/testData/checker/infos/CapturedInInlinedClosure.kt");
}
@TestMetadata("PropertiesWithBackingFields.kt")
public void testPropertiesWithBackingFields() throws Exception {
doTestWithInfos("idea/testData/checker/infos/PropertiesWithBackingFields.kt");