luaur_analysis/methods/
normalizer_union_strings.rs1use crate::records::normalized_string_type::NormalizedStringType;
2use crate::records::normalizer::Normalizer;
3use luaur_common::macros::luau_assert::LUAU_ASSERT;
4
5impl Normalizer {
6 pub fn union_strings(&mut self, here: &mut NormalizedStringType, there: &NormalizedStringType) {
7 self.consume_fuel();
8
9 if there.is_string() {
10 crate::methods::normalized_string_type_reset_to_string::normalized_string_type_reset_to_string(
11 here,
12 );
13 } else if here.is_union() && there.is_union() {
14 for (name, ty) in &there.singletons {
15 here.singletons.insert(name.clone(), *ty);
16 }
17 } else if here.is_union() && there.is_intersection() {
18 here.isCofinite = true;
19 for (name, ty) in &there.singletons {
20 if let Some(it) = here.singletons.remove(name) {
21 let _ = it;
22 } else {
23 here.singletons.insert(name.clone(), *ty);
24 }
25 }
26 } else if here.is_intersection() && there.is_union() {
27 for (name, _) in &there.singletons {
28 here.singletons.remove(name);
29 }
30 } else if here.is_intersection() && there.is_intersection() {
31 let mut keys_to_remove = Vec::new();
32 for (name, _) in &here.singletons {
33 if !there.singletons.contains_key(name) {
34 keys_to_remove.push(name.clone());
35 }
36 }
37 for name in keys_to_remove {
38 here.singletons.remove(&name);
39 }
40 } else {
41 LUAU_ASSERT!(false);
42 }
43 }
44}