No propagation of names bound in patterns to else-branches

This commit is contained in:
Andrey Breslav
2011-06-15 14:38:19 +04:00
parent e3dda48d09
commit 41d2c73c06
2 changed files with 7 additions and 42 deletions
@@ -1342,8 +1342,7 @@ public class JetTypeInferrer {
WritableScopeImpl thenScope = newWritableScopeImpl();
DataFlowInfo thenInfo = extractDataFlowInfoFromCondition(condition, true, thenScope);
WritableScopeImpl elseScope = newWritableScopeImpl();
DataFlowInfo elseInfo = extractDataFlowInfoFromCondition(condition, false, elseScope);
DataFlowInfo elseInfo = extractDataFlowInfoFromCondition(condition, false, null);
if (elseBranch == null) {
if (thenBranch != null) {
@@ -1356,7 +1355,7 @@ public class JetTypeInferrer {
}
}
else if (thenBranch == null) {
JetType type = getType(elseScope, elseBranch, true, elseInfo);
JetType type = getType(scope, elseBranch, true, elseInfo);
if (type != null && JetStandardClasses.isNothing(type)) {
resultDataFlowInfo = thenInfo;
// resultScope = thenScope;
@@ -1365,7 +1364,7 @@ public class JetTypeInferrer {
}
else {
JetType thenType = getType(thenScope, thenBranch, true, thenInfo);
JetType elseType = getType(elseScope, elseBranch, true, elseInfo);
JetType elseType = getType(scope, elseBranch, true, elseInfo);
if (thenType == null) {
result = elseType;
@@ -2335,41 +2334,7 @@ public class JetTypeInferrer {
@NotNull
@Override
public TypeInferrerVisitor createNew(JetScope scope, boolean preferBlock, DataFlowInfo dataFlowInfo) {
// if (scope instanceof WritableScope) {
// return new TypeInferrerVisitorWithWritableScope((WritableScope) scope, preferBlock, dataFlowInfo);
// }
return new TypeInferrerVisitorWithWritableScope(new WritableScopeImpl(scope, scope.getContainingDeclaration(), trace.getErrorHandler()), preferBlock, dataFlowInfo);
}
}
// private class CachedBindingTrace extends BindingTraceAdapter {
//
// public CachedBindingTrace(BindingTrace originalTrace) {
// super(originalTrace);
// }
//
// @Override
// public void recordExpressionType(@NotNull JetExpression expression, @NotNull JetType type) {
// super.recordExpressionType(expression, type);
// typeCache.put(expression, type);
// }
// }
private static class TypeAndDataFlowInfo {
private final JetType type;
private final DataFlowInfo dataFlowInfo;
private TypeAndDataFlowInfo(JetType type, DataFlowInfo dataFlowInfo) {
this.type = type;
this.dataFlowInfo = dataFlowInfo;
}
public JetType getType() {
return type;
}
public DataFlowInfo getDataFlowInfo() {
return dataFlowInfo;
}
}
}
+4 -4
View File
@@ -104,7 +104,7 @@ fun f13(a : A?) {
}
else {
a.foo()
<info descr="Automatically cast to B">c</info>.bar()
<error>c</error>.bar()
}
a?.foo()
@@ -122,11 +122,11 @@ fun f13(a : A?) {
<error>c</error>
}
else {
<info descr="Automatically cast to C">x</info>.bar()
<info descr="Automatically cast to B">c</info>.bar()
<error>x</error>
<error>c</error>
}
if (!(a is val <error>c</error> is B) || !(a is val <error>c</error> is C)) {
if (!(a is val c is B) || !(a is val c is C)) {
}
if (!(a is val c is B)) return