@@ -7,7 +7,7 @@ use smol_str::SmolStr;
77use crate :: {
88 check_type_compact,
99 db_index:: { DbIndex , LuaOperatorMetaMethod , LuaType } ,
10- LuaInferCache , LuaUnionType , TypeOps ,
10+ LuaInferCache , TypeOps ,
1111} ;
1212
1313use super :: { get_custom_type_operator, infer_expr, InferFailReason , InferResult } ;
@@ -28,11 +28,7 @@ pub fn infer_binary_expr(
2828 }
2929 }
3030
31- match ( & left_type, & right_type) {
32- ( LuaType :: Union ( u) , right) => infer_union ( db, & u, right, op, true ) ,
33- ( left, LuaType :: Union ( u) ) => infer_union ( db, & u, left, op, false ) ,
34- _ => infer_binary_expr_type ( db, left_type, right_type, op) ,
35- }
31+ infer_binary_expr_type ( db, left_type, right_type, op)
3632}
3733
3834fn infer_binary_expr_type (
@@ -67,49 +63,6 @@ fn infer_binary_expr_type(
6763 }
6864}
6965
70- fn infer_union (
71- db : & DbIndex ,
72- u : & LuaUnionType ,
73- right : & LuaType ,
74- op : BinaryOperator ,
75- union_is_left : bool ,
76- ) -> InferResult {
77- let mut unique_union_types = Vec :: new ( ) ;
78-
79- for ty in u. get_types ( ) {
80- let inferred_ty = if union_is_left {
81- infer_binary_expr_type ( db, ty. clone ( ) , right. clone ( ) , op) ?
82- } else {
83- infer_binary_expr_type ( db, right. clone ( ) , ty. clone ( ) , op) ?
84- } ;
85- flatten_and_insert ( inferred_ty, & mut unique_union_types) ;
86- }
87-
88- match unique_union_types. len ( ) {
89- 0 => Ok ( LuaType :: Unknown ) ,
90- 1 => Ok ( unique_union_types. into_iter ( ) . next ( ) . unwrap ( ) ) ,
91- _ => Ok ( LuaType :: Union ( LuaUnionType :: new ( unique_union_types) . into ( ) ) ) ,
92- }
93- }
94-
95- fn flatten_and_insert ( ty : LuaType , unique_union_types : & mut Vec < LuaType > ) {
96- let mut stack = vec ! [ ty] ;
97- while let Some ( current_ty) = stack. pop ( ) {
98- match current_ty {
99- LuaType :: Union ( u) => {
100- for inner_ty in u. get_types ( ) {
101- stack. push ( inner_ty. clone ( ) ) ;
102- }
103- }
104- _ => {
105- if !unique_union_types. contains ( & current_ty) {
106- unique_union_types. push ( current_ty) ;
107- }
108- }
109- }
110- }
111- }
112-
11366fn infer_binary_custom_operator (
11467 db : & DbIndex ,
11568 left : & LuaType ,
@@ -478,11 +431,21 @@ fn infer_cmp_expr(_: &DbIndex, left: LuaType, right: LuaType, op: BinaryOperator
478431 BinaryOperator :: OpNe => Ok ( LuaType :: BooleanConst ( i != j) ) ,
479432 _ => Ok ( LuaType :: Boolean ) ,
480433 } ,
434+ ( LuaType :: DocStringConst ( i) , LuaType :: StringConst ( j) ) => match op {
435+ BinaryOperator :: OpEq => Ok ( LuaType :: BooleanConst ( i == j) ) ,
436+ BinaryOperator :: OpNe => Ok ( LuaType :: BooleanConst ( i != j) ) ,
437+ _ => Ok ( LuaType :: Boolean ) ,
438+ } ,
481439 ( LuaType :: StringConst ( i) , LuaType :: StringConst ( j) ) => match op {
482440 BinaryOperator :: OpEq => Ok ( LuaType :: BooleanConst ( i == j) ) ,
483441 BinaryOperator :: OpNe => Ok ( LuaType :: BooleanConst ( i != j) ) ,
484442 _ => Ok ( LuaType :: Boolean ) ,
485443 } ,
444+ ( LuaType :: StringConst ( i) , LuaType :: DocStringConst ( j) ) => match op {
445+ BinaryOperator :: OpEq => Ok ( LuaType :: BooleanConst ( i == j) ) ,
446+ BinaryOperator :: OpNe => Ok ( LuaType :: BooleanConst ( i != j) ) ,
447+ _ => Ok ( LuaType :: Boolean ) ,
448+ } ,
486449 ( LuaType :: TableConst ( i) , LuaType :: TableConst ( j) ) => match op {
487450 BinaryOperator :: OpEq => Ok ( LuaType :: BooleanConst ( i == j) ) ,
488451 BinaryOperator :: OpNe => Ok ( LuaType :: BooleanConst ( i != j) ) ,
0 commit comments