KT-2906 If function parameter/variable is invoked in closure using parenthesis syntax, in IDEA it is not highlighted as captured in closure
#KT-2906 fixed
This commit is contained in:
@@ -39,6 +39,7 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.util.slicedmap.WritableSlice;
|
||||
@@ -149,6 +150,8 @@ public class CallResolver {
|
||||
JetSimpleNameExpression expression = (JetSimpleNameExpression) calleeExpression;
|
||||
functionReference = expression;
|
||||
|
||||
ExpressionTypingUtils.checkWrappingInRef(expression, context.trace, context.scope);
|
||||
|
||||
Name name = expression.getReferencedNameAsName();
|
||||
if (name == null) return checkArgumentTypesAndFail(context);
|
||||
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
// TODO : type substitutions???
|
||||
JetTypeInfo typeInfo = getSelectorReturnTypeInfo(NO_RECEIVER, null, expression, context);
|
||||
JetType type = DataFlowUtils.checkType(typeInfo.getType(), expression, context);
|
||||
ExpressionTypingUtils.checkWrappingInRef(expression, context);
|
||||
ExpressionTypingUtils.checkWrappingInRef(expression, context.trace, context.scope);
|
||||
return JetTypeInfo.create(type, typeInfo.getDataFlowInfo()); // TODO : Extensions to this
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -137,12 +137,12 @@ public class ExpressionTypingUtils {
|
||||
).contains(expression.getNode().getElementType());
|
||||
}
|
||||
|
||||
public static void checkWrappingInRef(JetSimpleNameExpression expression, ExpressionTypingContext context) {
|
||||
VariableDescriptor variable = BindingContextUtils.extractVariableDescriptorIfAny(context.trace.getBindingContext(), expression, true);
|
||||
public static void checkWrappingInRef(JetSimpleNameExpression expression, BindingTrace trace, JetScope scope) {
|
||||
VariableDescriptor variable = BindingContextUtils.extractVariableDescriptorIfAny(trace.getBindingContext(), expression, true);
|
||||
if (variable != null) {
|
||||
DeclarationDescriptor containingDeclaration = variable.getContainingDeclaration();
|
||||
if (context.scope.getContainingDeclaration() != containingDeclaration && containingDeclaration instanceof CallableDescriptor) {
|
||||
context.trace.record(CAPTURED_IN_CLOSURE, variable);
|
||||
if (scope.getContainingDeclaration() != containingDeclaration && containingDeclaration instanceof CallableDescriptor) {
|
||||
trace.record(CAPTURED_IN_CLOSURE, variable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
//KT-2906 If function parameter/variable is invoked in closure using parenthesis syntax, in IDEA it is not highlighted as captured in closure
|
||||
|
||||
package bug
|
||||
|
||||
public fun foo1(bar: () -> Unit) {
|
||||
run {
|
||||
bar() // ERROR: not highlighted as "captured in closure"
|
||||
}
|
||||
}
|
||||
|
||||
public fun foo2(bar: () -> Unit) {
|
||||
run {
|
||||
bar.invoke() // CORRECT: highlighted as "captured in closure"
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
foo1 { println ("foo1")} // prints "foo1"
|
||||
foo2 { println ("foo2")} // prints "foo2"
|
||||
}
|
||||
|
||||
fun <T> run(f: () -> T) : T = f()
|
||||
fun println(s: String) = s
|
||||
@@ -30,7 +30,7 @@ import org.jetbrains.jet.checkers.AbstractDiagnosticsTestWithEagerResolve;
|
||||
@InnerTestClasses({JetDiagnosticsTestGenerated.Tests.class, JetDiagnosticsTestGenerated.Script.class})
|
||||
public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEagerResolve {
|
||||
@TestMetadata("compiler/testData/diagnostics/tests")
|
||||
@InnerTestClasses({Tests.Annotations.class, Tests.BackingField.class, Tests.Cast.class, Tests.CheckArguments.class, Tests.ControlFlowAnalysis.class, Tests.ControlStructures.class, Tests.DataClasses.class, Tests.DataFlow.class, Tests.DataFlowInfoTraversal.class, Tests.DeclarationChecks.class, Tests.Enum.class, Tests.Extensions.class, Tests.Generics.class, Tests.IncompleteCode.class, Tests.Inference.class, Tests.Infos.class, Tests.J_k.class, Tests.Jdk_annotations.class, Tests.Library.class, Tests.NullabilityAndAutoCasts.class, Tests.Objects.class, Tests.OperatorsOverloading.class, Tests.Overload.class, Tests.Override.class, Tests.Redeclarations.class, Tests.Regressions.class, Tests.Scopes.class, Tests.Shadowing.class, Tests.Substitutions.class, Tests.Subtyping.class, Tests.Tuples.class, Tests.Varargs.class})
|
||||
@InnerTestClasses({Tests.Annotations.class, Tests.BackingField.class, Tests.Cast.class, Tests.CheckArguments.class, Tests.ControlFlowAnalysis.class, Tests.ControlStructures.class, Tests.DataClasses.class, Tests.DataFlow.class, Tests.DataFlowInfoTraversal.class, Tests.DeclarationChecks.class, Tests.Enum.class, Tests.Extensions.class, Tests.FunctionLiterals.class, Tests.Generics.class, Tests.IncompleteCode.class, Tests.Inference.class, Tests.Infos.class, Tests.J_k.class, Tests.Jdk_annotations.class, Tests.Library.class, Tests.NullabilityAndAutoCasts.class, Tests.Objects.class, Tests.OperatorsOverloading.class, Tests.Overload.class, Tests.Override.class, Tests.Redeclarations.class, Tests.Regressions.class, Tests.Scopes.class, Tests.Shadowing.class, Tests.Substitutions.class, Tests.Subtyping.class, Tests.Tuples.class, Tests.Varargs.class})
|
||||
public static class Tests extends AbstractDiagnosticsTestWithEagerResolve {
|
||||
@TestMetadata("Abstract.kt")
|
||||
public void testAbstract() throws Exception {
|
||||
@@ -1542,6 +1542,19 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/functionLiterals")
|
||||
public static class FunctionLiterals extends AbstractDiagnosticsTestWithEagerResolve {
|
||||
public void testAllFilesPresentInFunctionLiterals() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.checkers.AbstractDiagnosticsTestWithEagerResolve", new File("compiler/testData/diagnostics/tests/functionLiterals"), "kt", true);
|
||||
}
|
||||
|
||||
@TestMetadata("kt2906.kt")
|
||||
public void testKt2906() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/functionLiterals/kt2906.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/generics")
|
||||
public static class Generics extends AbstractDiagnosticsTestWithEagerResolve {
|
||||
public void testAllFilesPresentInGenerics() throws Exception {
|
||||
@@ -3496,6 +3509,7 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
||||
suite.addTest(DeclarationChecks.innerSuite());
|
||||
suite.addTest(Enum.innerSuite());
|
||||
suite.addTestSuite(Extensions.class);
|
||||
suite.addTestSuite(FunctionLiterals.class);
|
||||
suite.addTestSuite(Generics.class);
|
||||
suite.addTest(IncompleteCode.innerSuite());
|
||||
suite.addTest(Inference.innerSuite());
|
||||
|
||||
Reference in New Issue
Block a user