boolean checkUnionEquivalenceHelper ( UnionType that , EquivalenceMethod eqMethod , EqCache eqCache ) { List < JSType > thatAlternates = that . getAlternates ( ) ; if ( eqMethod == EquivalenceMethod . IDENTITY && alternates . size ( ) != thatAlternates . size ( ) ) { return false ; } for ( int i = 0 ; i < thatAlternates . size ( ) ; i ++ ) { JSType thatAlternate = thatAlternates . get ( i ) ; if ( ! hasAlternate ( thatAlternate , eqMethod , eqCache ) ) { return false ; } } return true ; }
Two union types are equal if after flattening nested union types they have the same number of alternates and all alternates are equal .