flow
flow copied to clipboard
Tagged union discrimination with multiple possible sentinels raises extraneous error
/* @flow */
type Outcome = "success" | "failure";
type Foo = { type: "foo", outcome: Outcome };
type Bar = { type: "bar", outcome: Outcome };
type FooBar = Foo | Bar;
declare var foobar: FooBar;
if (foobar.type === "foo") { } // error doesn't occur until this line
/path/to/test.js:4:20,24: string literal foo
Expected string literal bar, got foo instead
/path/to/test.js:5:20,24: string literal bar
Error path:
/path/to/test.js:4:20,24: StrT [string literal foo]
/path/to/test.js:5:20,24: ~> SingletonStrT [string literal bar] comes from
/path/to/test.js:4:20,24: . SingletonStrT [string literal foo]
/path/to/test.js:5:20,24: . ~> SingletonStrT [string literal bar] comes from
/path/to/test.js:5:12,44: . . ObjT [object type]
/path/to/test.js:4:12,44: . . ~> ObjT [object type] comes from
/path/to/test.js:6:15,23: . . . SpeculativeMatchFailureT [union type]
/path/to/test.js:4:12,44: . . . ~> ObjT [object type] comes from
/path/to/test.js:6:15,23: . . . . SpeculativeMatchFailureT [union type]
/path/to/test.js:6:15,17: . . . . ~> OpenT [Foo] comes from
/path/to/test.js:6:15,23: . . . . . SpeculativeMatchFailureT [union type]
/path/to/test.js:6:15,17: . . . . . ~> AnnotT [Foo] comes from
/path/to/test.js:5:12,44: . . . . . . ObjT [object type]
/path/to/test.js:6:15,23: . . . . . . ~> UnionT [union type] comes from
/path/to/test.js:5:12,44: . . . . . . . ObjT [object type]
/path/to/test.js:8:21,26: . . . . . . . ~> OpenT [FooBar] comes from
/path/to/test.js:5:12,44: . . . . . . . . ObjT [object type]
/path/to/test.js:8:21,26: . . . . . . . . ~> AnnotT [FooBar] comes from
/path/to/test.js:10:21,25: . . . . . . . . . StrT [string]
/path/to/test.js:10:1,11:1: . . . . . . . . . ~> PredicateT [identifier foobar when not left operand of sentinel prop type with right operand = string] comes from
/path/to/test.js:5:12,44: . . . . . . . . . . ObjT [object type]
/path/to/test.js:10:1,11:1: . . . . . . . . . . ~> PredicateT [identifier foobar when not left operand of sentinel prop type with right operand = string] comes from
/path/to/test.js:6:21,23: . . . . . . . . . . . OpenT [Bar]
/path/to/test.js:10:1,11:1: . . . . . . . . . . . ~> PredicateT [identifier foobar when not left operand of sentinel prop type with right operand = string] comes from
/path/to/test.js:6:21,23: . . . . . . . . . . . . AnnotT [Bar]
/path/to/test.js:10:1,11:1: . . . . . . . . . . . . ~> PredicateT [identifier foobar when not left operand of sentinel prop type with right operand = string] comes from
/path/to/test.js:6:15,23: . . . . . . . . . . . . . UnionT [union type]
/path/to/test.js:10:1,11:1: . . . . . . . . . . . . . ~> PredicateT [identifier foobar when not left operand of sentinel prop type with right operand = string] comes from
/path/to/test.js:8:21,26: . . . . . . . . . . . . . . OpenT [FooBar]
/path/to/test.js:10:1,11:1: . . . . . . . . . . . . . . ~> PredicateT [identifier foobar when not left operand of sentinel prop type with right operand = string] comes from
/path/to/test.js:8:21,26: . . . . . . . . . . . . . . . AnnotT [FooBar]
/path/to/test.js:10:1,11:1: . . . . . . . . . . . . . . . ~> PredicateT [identifier foobar when not left operand of sentinel prop type with right operand = string]
/path/to/test.js:5:20,24: string literal bar
Expected string literal foo, got bar instead
/path/to/test.js:4:20,24: string literal foo
Error path:
/path/to/test.js:5:20,24: StrT [string literal bar]
/path/to/test.js:4:20,24: ~> SingletonStrT [string literal foo] comes from
/path/to/test.js:5:20,24: . SingletonStrT [string literal bar]
/path/to/test.js:4:20,24: . ~> SingletonStrT [string literal foo] comes from
/path/to/test.js:5:12,44: . . ObjT [object type]
/path/to/test.js:4:12,44: . . ~> ObjT [object type] comes from
/path/to/test.js:6:15,23: . . . SpeculativeMatchFailureT [union type]
/path/to/test.js:4:12,44: . . . ~> ObjT [object type] comes from
/path/to/test.js:6:15,23: . . . . SpeculativeMatchFailureT [union type]
/path/to/test.js:6:15,17: . . . . ~> OpenT [Foo] comes from
/path/to/test.js:6:15,23: . . . . . SpeculativeMatchFailureT [union type]
/path/to/test.js:6:15,17: . . . . . ~> AnnotT [Foo] comes from
/path/to/test.js:5:12,44: . . . . . . ObjT [object type]
/path/to/test.js:6:15,23: . . . . . . ~> UnionT [union type] comes from
/path/to/test.js:5:12,44: . . . . . . . ObjT [object type]
/path/to/test.js:8:21,26: . . . . . . . ~> OpenT [FooBar] comes from
/path/to/test.js:5:12,44: . . . . . . . . ObjT [object type]
/path/to/test.js:8:21,26: . . . . . . . . ~> AnnotT [FooBar] comes from
/path/to/test.js:10:21,25: . . . . . . . . . StrT [string]
/path/to/test.js:10:1,11:1: . . . . . . . . . ~> PredicateT [identifier foobar when not left operand of sentinel prop type with right operand = string] comes from
/path/to/test.js:5:12,44: . . . . . . . . . . ObjT [object type]
/path/to/test.js:10:1,11:1: . . . . . . . . . . ~> PredicateT [identifier foobar when not left operand of sentinel prop type with right operand = string] comes from
/path/to/test.js:6:21,23: . . . . . . . . . . . OpenT [Bar]
/path/to/test.js:10:1,11:1: . . . . . . . . . . . ~> PredicateT [identifier foobar when not left operand of sentinel prop type with right operand = string] comes from
/path/to/test.js:6:21,23: . . . . . . . . . . . . AnnotT [Bar]
/path/to/test.js:10:1,11:1: . . . . . . . . . . . . ~> PredicateT [identifier foobar when not left operand of sentinel prop type with right operand = string] comes from
/path/to/test.js:6:15,23: . . . . . . . . . . . . . UnionT [union type]
/path/to/test.js:10:1,11:1: . . . . . . . . . . . . . ~> PredicateT [identifier foobar when not left operand of sentinel prop type with right operand = string] comes from
/path/to/test.js:8:21,26: . . . . . . . . . . . . . . OpenT [FooBar]
/path/to/test.js:10:1,11:1: . . . . . . . . . . . . . . ~> PredicateT [identifier foobar when not left operand of sentinel prop type with right operand = string] comes from
/path/to/test.js:8:21,26: . . . . . . . . . . . . . . . AnnotT [FooBar]
/path/to/test.js:10:1,11:1: . . . . . . . . . . . . . . . ~> PredicateT [identifier foobar when not left operand of sentinel prop type with right operand = string]
Maybe a good one for you, Avik? cc @avikchaudhuri
Is anyone working on this at all? @samwgoldman
@zgao Not to my knowledge. I was hoping Avik would see this, because I haven't fully grokked the code for tagged union discrimination.
Weird. This is related to #1116. Changing the type prop to atype fixes the issue. Closing this to consolidate with #1116.