mago_analyzer/reconciler/
macros.rs1#[macro_export]
2macro_rules! intersect_simple {
3 (
4 $(|)? $( $subtype_pattern:pat_param )|+ $( if $subtype_guard: expr )? $(,)?,
5 $(|)? $( $supertype_pattern:pat_param )|+ $( if $supertype_guard: expr )? $(,)?,
6 $context:expr,
7 $max_type:expr,
8 $assertion:expr,
9 $existing_var_type:expr,
10 $key:expr,
11 $negated:expr,
12 $span:expr,
13 $is_equality:expr,
14 ) => {
15 {
16 let mut acceptable_types = Vec::new();
17 let mut did_remove_type = false;
18
19 for atomic in $existing_var_type.types.as_ref() {
20 if matches!(atomic, $( $subtype_pattern )|+ $( if $subtype_guard )?) {
21 acceptable_types.push(atomic.clone());
22 } else if matches!(atomic, $( $supertype_pattern )|+ $( if $supertype_guard )?) {
23 return Some($max_type);
24 } else if let TAtomic::Variable(_) = atomic {
25 did_remove_type = true;
26 acceptable_types.push(atomic.clone());
27 } else {
28 did_remove_type = true;
29 }
30 }
31
32 if acceptable_types.is_empty() || (!did_remove_type && !$is_equality) {
33 if let Some(k) = $key {
34 if let Some(span) = $span {
35 trigger_issue_for_impossible(
36 $context,
37 $existing_var_type.get_id(),
38 &k,
39 $assertion,
40 !did_remove_type,
41 $negated,
42 span,
43 );
44 }
45 }
46 }
47
48 if !acceptable_types.is_empty() {
49 return Some(TUnion::from_vec(acceptable_types));
50 }
51
52 Some(get_never())
53 }
54 }
55}