1- use std:: collections:: HashSet ;
2-
31use emmylua_parser:: { BinaryOperator , LuaBinaryExpr } ;
42use smol_str:: SmolStr ;
53
@@ -63,7 +61,7 @@ fn infer_binary_expr_type(
6361}
6462
6563fn infer_union ( db : & DbIndex , u : & LuaUnionType , right : & LuaType , op : BinaryOperator ) -> InferResult {
66- let mut unique_union_types = HashSet :: new ( ) ;
64+ let mut unique_union_types = Vec :: new ( ) ;
6765
6866 for ty in u. get_types ( ) {
6967 let inferred_ty = infer_binary_expr_type ( db, ty. clone ( ) , right. clone ( ) , op) ?;
@@ -74,12 +72,12 @@ fn infer_union(db: &DbIndex, u: &LuaUnionType, right: &LuaType, op: BinaryOperat
7472 0 => Some ( LuaType :: Unknown ) ,
7573 1 => Some ( unique_union_types. into_iter ( ) . next ( ) . unwrap ( ) ) ,
7674 _ => Some ( LuaType :: Union (
77- LuaUnionType :: new ( unique_union_types. into_iter ( ) . collect ( ) ) . into ( ) ,
75+ LuaUnionType :: new ( unique_union_types) . into ( ) ,
7876 ) ) ,
7977 }
8078}
8179
82- fn flatten_and_insert ( ty : LuaType , unique_union_types : & mut HashSet < LuaType > ) {
80+ fn flatten_and_insert ( ty : LuaType , unique_union_types : & mut Vec < LuaType > ) {
8381 let mut stack = vec ! [ ty] ;
8482 while let Some ( current_ty) = stack. pop ( ) {
8583 match current_ty {
@@ -89,7 +87,9 @@ fn flatten_and_insert(ty: LuaType, unique_union_types: &mut HashSet<LuaType>) {
8987 }
9088 }
9189 _ => {
92- unique_union_types. insert ( current_ty) ;
90+ if !unique_union_types. contains ( & current_ty) {
91+ unique_union_types. push ( current_ty) ;
92+ }
9393 }
9494 }
9595 }
0 commit comments