Fixed DFA for the last assignment / initialization in block. A relevant test. #KT-7599 Fixed.
This commit is contained in:
+3
-2
@@ -294,9 +294,10 @@ public class ExpressionTypingServices {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mightBeUnit) {
|
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());
|
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;
|
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);
|
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")
|
@TestMetadata("property.kt")
|
||||||
public void testProperty() throws Exception {
|
public void testProperty() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/variables/property.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/variables/property.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user