No propagation of names bound in patterns to else-branches
This commit is contained in:
@@ -1342,8 +1342,7 @@ public class JetTypeInferrer {
|
|||||||
|
|
||||||
WritableScopeImpl thenScope = newWritableScopeImpl();
|
WritableScopeImpl thenScope = newWritableScopeImpl();
|
||||||
DataFlowInfo thenInfo = extractDataFlowInfoFromCondition(condition, true, thenScope);
|
DataFlowInfo thenInfo = extractDataFlowInfoFromCondition(condition, true, thenScope);
|
||||||
WritableScopeImpl elseScope = newWritableScopeImpl();
|
DataFlowInfo elseInfo = extractDataFlowInfoFromCondition(condition, false, null);
|
||||||
DataFlowInfo elseInfo = extractDataFlowInfoFromCondition(condition, false, elseScope);
|
|
||||||
|
|
||||||
if (elseBranch == null) {
|
if (elseBranch == null) {
|
||||||
if (thenBranch != null) {
|
if (thenBranch != null) {
|
||||||
@@ -1356,7 +1355,7 @@ public class JetTypeInferrer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (thenBranch == null) {
|
else if (thenBranch == null) {
|
||||||
JetType type = getType(elseScope, elseBranch, true, elseInfo);
|
JetType type = getType(scope, elseBranch, true, elseInfo);
|
||||||
if (type != null && JetStandardClasses.isNothing(type)) {
|
if (type != null && JetStandardClasses.isNothing(type)) {
|
||||||
resultDataFlowInfo = thenInfo;
|
resultDataFlowInfo = thenInfo;
|
||||||
// resultScope = thenScope;
|
// resultScope = thenScope;
|
||||||
@@ -1365,7 +1364,7 @@ public class JetTypeInferrer {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
JetType thenType = getType(thenScope, thenBranch, true, thenInfo);
|
JetType thenType = getType(thenScope, thenBranch, true, thenInfo);
|
||||||
JetType elseType = getType(elseScope, elseBranch, true, elseInfo);
|
JetType elseType = getType(scope, elseBranch, true, elseInfo);
|
||||||
|
|
||||||
if (thenType == null) {
|
if (thenType == null) {
|
||||||
result = elseType;
|
result = elseType;
|
||||||
@@ -2335,41 +2334,7 @@ public class JetTypeInferrer {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public TypeInferrerVisitor createNew(JetScope scope, boolean preferBlock, DataFlowInfo dataFlowInfo) {
|
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);
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ fun f13(a : A?) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
a.foo()
|
a.foo()
|
||||||
<info descr="Automatically cast to B">c</info>.bar()
|
<error>c</error>.bar()
|
||||||
}
|
}
|
||||||
|
|
||||||
a?.foo()
|
a?.foo()
|
||||||
@@ -122,11 +122,11 @@ fun f13(a : A?) {
|
|||||||
<error>c</error>
|
<error>c</error>
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
<info descr="Automatically cast to C">x</info>.bar()
|
<error>x</error>
|
||||||
<info descr="Automatically cast to B">c</info>.bar()
|
<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
|
if (!(a is val c is B)) return
|
||||||
|
|||||||
Reference in New Issue
Block a user