Skip to content

Commit ad93aec

Browse files
authored
Port "Fix of #58996" (#1802)
1 parent d5215bc commit ad93aec

File tree

5 files changed

+5
-20
lines changed

5 files changed

+5
-20
lines changed

internal/checker/checker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19746,7 +19746,7 @@ func (c *Checker) checkIfExpressionRefinesParameter(fn *ast.Node, expr *ast.Node
1974619746
// "x is T" means that x is T if and only if it returns true. If it returns false then x is not T.
1974719747
// This means that if the function is called with an argument of type trueType, there can't be anything left in the `else` branch. It must reduce to `never`.
1974819748
falseCondition := &ast.FlowNode{Flags: ast.FlowFlagsFalseCondition, Node: expr, Antecedent: antecedent}
19749-
falseSubtype := c.getFlowTypeOfReferenceEx(param.Name(), initType, trueType, fn, falseCondition)
19749+
falseSubtype := c.getReducedType(c.getFlowTypeOfReferenceEx(param.Name(), initType, trueType, fn, falseCondition))
1975019750
if falseSubtype.flags&TypeFlagsNever != 0 {
1975119751
return trueType
1975219752
}

testdata/baselines/reference/submodule/compiler/inferTypePredicates.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,4 +648,4 @@ type Rock = {
648648
type Something = Animal | Rock;
649649
declare function isAnimal(something: Something): something is Animal;
650650
declare function positive(t: Something): t is Animal;
651-
declare function negative(t: Something): boolean;
651+
declare function negative(t: Something): t is Rock;

testdata/baselines/reference/submodule/compiler/inferTypePredicates.js.diff

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,4 @@
5858
+}) => fb is {
5959
type: "foo";
6060
foo: number;
61-
};
62-
@@= skipped -15, +21 lines =@@
63-
type Something = Animal | Rock;
64-
declare function isAnimal(something: Something): something is Animal;
65-
declare function positive(t: Something): t is Animal;
66-
-declare function negative(t: Something): t is Rock;
67-
+declare function negative(t: Something): boolean;
61+
};

testdata/baselines/reference/submodule/compiler/inferTypePredicates.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ function positive(t: Something) {
10921092
}
10931093

10941094
function negative(t: Something) {
1095-
>negative : (t: Something) => boolean
1095+
>negative : (t: Something) => t is Rock
10961096
>t : Something
10971097

10981098
return !isAnimal(t)

testdata/baselines/reference/submodule/compiler/inferTypePredicates.types.diff

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,4 @@
141141
+>foobarPred : (fb: { type: "foo"; foo: number; } | { type: "bar"; bar: string; }) => fb is { type: "foo"; foo: number; }
142142
>foobar : { type: "foo"; foo: number; } | { type: "bar"; bar: string; }
143143

144-
foobar.foo;
145-
@@= skipped -88, +88 lines =@@
146-
}
147-
148-
function negative(t: Something) {
149-
->negative : (t: Something) => t is Rock
150-
+>negative : (t: Something) => boolean
151-
>t : Something
152-
153-
return !isAnimal(t)
144+
foobar.foo;

0 commit comments

Comments
 (0)