Fix tests (by extracting a method and calling it multiple times)

This commit is contained in:
Andrey Breslav
2013-04-18 17:35:41 +04:00
parent 140382e280
commit fe4dd2f661
5 changed files with 29 additions and 15 deletions
@@ -754,10 +754,6 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
JetExpression right = expression.getRight(); JetExpression right = expression.getRight();
IElementType operationType = operationSign.getReferencedNameElementType(); IElementType operationType = operationSign.getReferencedNameElementType();
JetTypeInfo leftTypeInfo = left != null
? facade.getTypeInfo(left, context)
: JetTypeInfo.create(null, context.dataFlowInfo);
JetType result = null; JetType result = null;
DataFlowInfo dataFlowInfo = context.dataFlowInfo; DataFlowInfo dataFlowInfo = context.dataFlowInfo;
@@ -801,6 +797,8 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
if (right != null && left != null) { if (right != null && left != null) {
ExpressionReceiver receiver = ExpressionTypingUtils.safeGetExpressionReceiver(facade, left, context); ExpressionReceiver receiver = ExpressionTypingUtils.safeGetExpressionReceiver(facade, left, context);
JetTypeInfo leftTypeInfo = getTypeInfoOrNullType(left, context, facade);
dataFlowInfo = leftTypeInfo.getDataFlowInfo(); dataFlowInfo = leftTypeInfo.getDataFlowInfo();
ExpressionTypingContext contextWithDataFlow = context.replaceDataFlowInfo(dataFlowInfo); ExpressionTypingContext contextWithDataFlow = context.replaceDataFlowInfo(dataFlowInfo);
@@ -843,6 +841,8 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
result = typeInfo.getType(); result = typeInfo.getType();
} }
else if (OperatorConventions.BOOLEAN_OPERATIONS.containsKey(operationType)) { else if (OperatorConventions.BOOLEAN_OPERATIONS.containsKey(operationType)) {
JetTypeInfo leftTypeInfo = getTypeInfoOrNullType(left, context, facade);
JetType leftType = leftTypeInfo.getType(); JetType leftType = leftTypeInfo.getType();
dataFlowInfo = leftTypeInfo.getDataFlowInfo(); dataFlowInfo = leftTypeInfo.getDataFlowInfo();
@@ -865,6 +865,8 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
result = booleanType; result = booleanType;
} }
else if (operationType == JetTokens.ELVIS) { else if (operationType == JetTokens.ELVIS) {
JetTypeInfo leftTypeInfo = getTypeInfoOrNullType(left, context, facade);
JetType leftType = leftTypeInfo.getType(); JetType leftType = leftTypeInfo.getType();
dataFlowInfo = leftTypeInfo.getDataFlowInfo(); dataFlowInfo = leftTypeInfo.getDataFlowInfo();
@@ -467,4 +467,15 @@ public class ExpressionTypingUtils {
} }
}; };
} }
@NotNull
public static JetTypeInfo getTypeInfoOrNullType(
@Nullable JetExpression expression,
@NotNull ExpressionTypingContext context,
@NotNull ExpressionTypingInternals facade
) {
return expression != null
? facade.getTypeInfo(expression, context)
: JetTypeInfo.create(null, context.dataFlowInfo);
}
} }
@@ -209,9 +209,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
JetSimpleNameExpression operationSign = expression.getOperationReference(); JetSimpleNameExpression operationSign = expression.getOperationReference();
IElementType operationType = operationSign.getReferencedNameElementType(); IElementType operationType = operationSign.getReferencedNameElementType();
JetExpression leftOperand = expression.getLeft(); JetExpression leftOperand = expression.getLeft();
JetTypeInfo leftInfo = leftOperand != null JetTypeInfo leftInfo = ExpressionTypingUtils.getTypeInfoOrNullType(leftOperand, context, facade);
? facade.getTypeInfo(leftOperand, context)
: JetTypeInfo.create(null, context.dataFlowInfo);
JetType leftType = leftInfo.getType(); JetType leftType = leftInfo.getType();
DataFlowInfo dataFlowInfo = leftInfo.getDataFlowInfo(); DataFlowInfo dataFlowInfo = leftInfo.getDataFlowInfo();
@@ -294,9 +292,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
return JetTypeInfo.create(checkAssignmentType(typeInfo.getType(), expression, contextWithExpectedType), return JetTypeInfo.create(checkAssignmentType(typeInfo.getType(), expression, contextWithExpectedType),
typeInfo.getDataFlowInfo()); typeInfo.getDataFlowInfo());
} }
JetTypeInfo leftInfo = leftOperand != null JetTypeInfo leftInfo = ExpressionTypingUtils.getTypeInfoOrNullType(left, context, facade);
? facade.getTypeInfo(leftOperand, context)
: JetTypeInfo.create(null, context.dataFlowInfo);
JetType leftType = leftInfo.getType(); JetType leftType = leftInfo.getType();
DataFlowInfo dataFlowInfo = leftInfo.getDataFlowInfo(); DataFlowInfo dataFlowInfo = leftInfo.getDataFlowInfo();
if (right != null) { if (right != null) {
@@ -0,0 +1,3 @@
fun test(x: Int?) {
<!TYPE_MISMATCH!>x<!> in 1..2
}
@@ -16,17 +16,14 @@
package org.jetbrains.jet.checkers; package org.jetbrains.jet.checkers;
import junit.framework.Assert;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestSuite; import junit.framework.TestSuite;
import java.io.File;
import java.util.regex.Pattern;
import org.jetbrains.jet.JetTestUtils; import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.test.InnerTestClasses; import org.jetbrains.jet.test.InnerTestClasses;
import org.jetbrains.jet.test.TestMetadata; import org.jetbrains.jet.test.TestMetadata;
import org.jetbrains.jet.checkers.AbstractDiagnosticsTestWithEagerResolve; import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */ /** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all") @SuppressWarnings("all")
@@ -3050,6 +3047,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
doTest("compiler/testData/diagnostics/tests/nullableTypes/nullAssertOnTypeWithNullableUpperBound.kt"); doTest("compiler/testData/diagnostics/tests/nullableTypes/nullAssertOnTypeWithNullableUpperBound.kt");
} }
@TestMetadata("nullableArgumentForIn.kt")
public void testNullableArgumentForIn() throws Exception {
doTest("compiler/testData/diagnostics/tests/nullableTypes/nullableArgumentForIn.kt");
}
@TestMetadata("redundantNullable.kt") @TestMetadata("redundantNullable.kt")
public void testRedundantNullable() throws Exception { public void testRedundantNullable() throws Exception {
doTest("compiler/testData/diagnostics/tests/nullableTypes/redundantNullable.kt"); doTest("compiler/testData/diagnostics/tests/nullableTypes/redundantNullable.kt");