-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
Typing: soundnessNo false negatives (type checker claims that there is no error in the incorrect program)No false negatives (type checker claims that there is no error in the incorrect program)
Description
The following code should raise an error, but doesn't:
const a = [1];
function foo(arr: (number|string)[]) {
arr.push("x");
}
foo(a);
function bar(arr: number[]) { }
bar(a);This problem seems to be specific to arrays. If I replace all T[] with {x: T}, then I get the expected behavior.
Flow version: v0.146.0
Expected behavior
Either an error on foo(a), or an error on bar(a). If a is inferred to be number[], then foo(a) should be an error. If it's inferred to be (number|string)[], then bar(a) should be an error.
Actual behavior
When the type of the array is left off (inferred), it seems to produce unsound results. When the type is explicitly specified I get the expected results.
Metadata
Metadata
Assignees
Labels
Typing: soundnessNo false negatives (type checker claims that there is no error in the incorrect program)No false negatives (type checker claims that there is no error in the incorrect program)