flow icon indicating copy to clipboard operation
flow copied to clipboard

Tagged union discrimination with multiple possible sentinels raises extraneous error

Open samwgoldman opened this issue 11 years ago • 4 comments

/* @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]

samwgoldman avatar Sep 02 '15 22:09 samwgoldman

Maybe a good one for you, Avik? cc @avikchaudhuri

samwgoldman avatar Sep 02 '15 22:09 samwgoldman

Is anyone working on this at all? @samwgoldman

zgao avatar Nov 14 '15 00:11 zgao

@zgao Not to my knowledge. I was hoping Avik would see this, because I haven't fully grokked the code for tagged union discrimination.

samwgoldman avatar Nov 14 '15 00:11 samwgoldman

Weird. This is related to #1116. Changing the type prop to atype fixes the issue. Closing this to consolidate with #1116.

samwgoldman avatar Nov 19 '15 20:11 samwgoldman