KT-1743 Analyze immutable local variables and parameters which are captured in closure

#KT-1743 fixed
This commit is contained in:
Svetlana Isakova
2012-05-03 17:56:45 +04:00
parent 08abd992c9
commit d4b816ef56
4 changed files with 17 additions and 17 deletions
@@ -943,7 +943,7 @@ public class JetTypeMapper {
}
else if (descriptor instanceof VariableDescriptor) {
Boolean aBoolean = bindingContext.get(BindingContext.MUST_BE_WRAPPED_IN_A_REF, (VariableDescriptor) descriptor);
if (aBoolean != null && aBoolean) {
if (aBoolean != null && aBoolean && ((VariableDescriptor) descriptor).isVar()) {
JetType outType = ((VariableDescriptor) descriptor).getType();
return StackValue.sharedTypeForType(mapType(outType, MapTypeMode.VALUE));
}
@@ -134,7 +134,7 @@ public class ExpressionTypingUtils {
public static void checkWrappingInRef(JetSimpleNameExpression expression, ExpressionTypingContext context) {
VariableDescriptor variable = BindingContextUtils.extractVariableDescriptorIfAny(context.trace.getBindingContext(), expression, true);
if (variable != null && variable.isVar()) {
if (variable != null) {
DeclarationDescriptor containingDeclaration = variable.getContainingDeclaration();
if (context.scope.getContainingDeclaration() != containingDeclaration && containingDeclaration instanceof CallableDescriptor) {
context.trace.record(MUST_BE_WRAPPED_IN_A_REF, variable);
@@ -328,7 +328,7 @@ fun func() {
val <!UNUSED_VARIABLE!>a<!> = object {
val x = b
{
<!VAL_REASSIGNMENT!>b<!> = <!UNUSED_VALUE!>4<!>
<!VAL_REASSIGNMENT!>b<!> = 4
<!UNRESOLVED_REFERENCE!>$b<!> = 3
}
}
+14 -14
View File
@@ -184,31 +184,31 @@ fun vars(a: Any?) {
b = <info descr="Automatically cast to jet.Int"><warning>a</warning></info>
}
}
fun tuples(a: Any?) {
if (a != null) {
val <warning>s</warning>: #(Any, String) = #(<info descr="Automatically cast to jet.Any">a</info>, <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is jet.Any? but jet.String was expected">a</error>)
fun tuples(<info>a</info>: Any?) {
if (<info>a</info> != null) {
val <warning>s</warning>: #(Any, String) = #(<info descr="Automatically cast to jet.Any"><info>a</info></info>, <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is jet.Any? but jet.String was expected">a</error>)
}
if (a is String) {
val <warning>s</warning>: #(Any, String) = #(<info descr="Automatically cast to jet.Any">a</info>, <info descr="Automatically cast to jet.String">a</info>)
if (<info>a</info> is String) {
val <warning>s</warning>: #(Any, String) = #(<info descr="Automatically cast to jet.Any"><info>a</info></info>, <info descr="Automatically cast to jet.String"><info>a</info></info>)
}
fun illegalTupleReturnType(): #(Any, String) = #(<error descr="[TYPE_MISMATCH] Type mismatch: inferred type is jet.Any? but jet.Any was expected">a</error>, <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is jet.Any? but jet.String was expected">a</error>)
if (a is String) {
fun legalTupleReturnType(): #(Any, String) = #(<info descr="Automatically cast to jet.Any">a</info>, <info descr="Automatically cast to jet.String">a</info>)
if (<info>a</info> is String) {
fun legalTupleReturnType(): #(Any, String) = #(<info descr="Automatically cast to jet.Any"><info>a</info></info>, <info descr="Automatically cast to jet.String"><info>a</info></info>)
}
val <warning>illegalFunctionLiteral</warning>: Function0<Int> = <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is () -> jet.Any? but () -> jet.Int was expected">{ <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is jet.Any? but jet.Int was expected">a</error> }</error>
val <warning>illegalReturnValueInFunctionLiteral</warning>: Function0<Int> = { (): Int -> <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is jet.Any? but jet.Int was expected">a</error> }
if (a is Int) {
val <warning>legalFunctionLiteral</warning>: Function0<Int> = { <info descr="Automatically cast to jet.Int">a</info> }
val <warning>alsoLegalFunctionLiteral</warning>: Function0<Int> = { (): Int -> <info descr="Automatically cast to jet.Int">a</info> }
if (<info>a</info> is Int) {
val <warning>legalFunctionLiteral</warning>: Function0<Int> = { <info><info descr="Automatically cast to jet.Int">a</info></info> }
val <warning>alsoLegalFunctionLiteral</warning>: Function0<Int> = { (): Int -> <info descr="Automatically cast to jet.Int"><info>a</info></info> }
}
}
fun returnFunctionLiteralBlock(a: Any?): Function0<Int> {
if (a is Int) return { <info descr="Automatically cast to jet.Int">a</info> }
fun returnFunctionLiteralBlock(<info>a</info>: Any?): Function0<Int> {
if (<info>a</info> is Int) return { <info><info descr="Automatically cast to jet.Int">a</info></info> }
else return { 1 }
}
fun returnFunctionLiteral(a: Any?): Function0<Int> =
if (a is Int) { (): Int -> <info descr="Automatically cast to jet.Int">a</info> }
fun returnFunctionLiteral(<info>a</info>: Any?): Function0<Int> =
if (<info>a</info> is Int) { (): Int -> <info descr="Automatically cast to jet.Int"><info>a</info></info> }
else { () -> 1 }
fun illegalTupleReturnType(a: Any): #(Any, String) = #(a, <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is jet.Any but jet.String was expected">a</error>)