Fixed DFA for the last assignment / initialization in block. A relevant test. #KT-7599 Fixed.

This commit is contained in:
Mikhail Glukhikh
2015-04-27 19:30:02 +03:00
parent 60fdfb8441
commit 8f2a3e9d5f
4 changed files with 58 additions and 2 deletions
@@ -294,9 +294,10 @@ public class ExpressionTypingServices {
}
}
if (mightBeUnit) {
// ExpressionTypingVisitorForStatements should return only null or Unit for declarations and assignments
// ExpressionTypingVisitorForStatements should return only null or Unit for declarations and assignments,
// but (for correct assignment / initialization analysis) data flow info must be preserved
assert result.getType() == null || KotlinBuiltIns.isUnit(result.getType());
result = result.replaceType(expressionTypingComponents.builtIns.getUnitType()).replaceDataFlowInfo(context.dataFlowInfo);
result = result.replaceType(expressionTypingComponents.builtIns.getUnitType());
}
}
return result;
@@ -0,0 +1,23 @@
trait A {
fun ok(): Boolean
}
class B: A {
override fun ok(): Boolean { return true }
}
class C: A {
override fun ok(): Boolean { return false }
}
fun foo(): Boolean {
var v: A
v = B()
// No smart cast needed, but not a problem if ever
if (<!DEBUG_INFO_SMARTCAST!>v<!>.ok()) {
v = C()
}
// No smart cast needed, and no smart cast possible!
// We cannot choose between B and C
return v.ok()
}
@@ -0,0 +1,26 @@
package
internal fun foo(): kotlin.Boolean
internal trait A {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
internal abstract fun ok(): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
internal final class B : A {
public constructor B()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
internal open override /*1*/ fun ok(): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
internal final class C : A {
public constructor C()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
internal open override /*1*/ fun ok(): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -11672,6 +11672,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("kt7599.kt")
public void testKt7599() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/variables/kt7599.kt");
doTest(fileName);
}
@TestMetadata("property.kt")
public void testProperty() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/variables/property.kt");