Skip to main content

sql_fun_sqlast/sem/problem/
overload_resolution.rs

1use crate::sem::{
2    FullName, OperatorDefinition, TypeReference, type_system::ArgumentBindingCollection,
3};
4
5#[derive(Debug, Clone)]
6pub enum OverloadResolution {
7    /// function overload resolve failed
8    FunctionOverloadResolutionFailed(FullName, ArgumentBindingCollection),
9
10    /// Binary operator overload resolve failed
11    BinaryOperatorOverloadResolutionFailed(OperatorDefinition, TypeReference, TypeReference),
12
13    /// Unary operator overload resove failed
14    UnaryOperatorOverloadResolutionFailed(OperatorDefinition, TypeReference),
15
16    /// Ambiguous operator overload
17    BinaryOperatorOverloadAmbiguous(OperatorDefinition, TypeReference, TypeReference),
18
19    /// Unary operator overload ambiguous
20    UnaryOperatorOverloadAmbiguous(OperatorDefinition, TypeReference),
21}
22
23impl OverloadResolution {
24    /// function argument type missmatch to overloads
25    pub fn function_overload_resolution_failed(
26        func_name: &FullName,
27        arg_types: &ArgumentBindingCollection,
28    ) -> Self {
29        Self::FunctionOverloadResolutionFailed(func_name.clone(), arg_types.to_owned())
30    }
31
32    /// Binary operator type not matches overloads
33    pub fn binary_operator_overload_resolution_failed(
34        operator_def: &OperatorDefinition,
35        left_type: &TypeReference,
36        right_type: &TypeReference,
37    ) -> Self {
38        Self::BinaryOperatorOverloadResolutionFailed(
39            operator_def.clone(),
40            left_type.clone(),
41            right_type.clone(),
42        )
43    }
44
45    /// Unarry operator type not matches overloads
46    pub fn unary_operator_overload_resolution_failed(
47        operator_def: &OperatorDefinition,
48        arg_type: &TypeReference,
49    ) -> Self {
50        Self::UnaryOperatorOverloadResolutionFailed(operator_def.clone(), arg_type.clone())
51    }
52
53    /// Binary operaot type overloads ambiguous
54    pub fn binary_operator_overload_ambiguous(
55        operator_def: &OperatorDefinition,
56        left_type: &TypeReference,
57        right_type: &TypeReference,
58    ) -> Self {
59        Self::BinaryOperatorOverloadAmbiguous(
60            operator_def.clone(),
61            left_type.clone(),
62            right_type.clone(),
63        )
64    }
65
66    /// Unarray operator type ambiguous
67    pub fn unary_operator_overload_ambiguous(
68        operator_def: &OperatorDefinition,
69        arg_type: &TypeReference,
70    ) -> Self {
71        Self::UnaryOperatorOverloadAmbiguous(operator_def.clone(), arg_type.clone())
72    }
73}
74
75impl super::AnalysisProblem {
76    /// function argument type missmatch to overloads
77    #[tracing::instrument()]
78    pub fn function_overload_resolution_failed(
79        func_name: &FullName,
80        arg_types: &ArgumentBindingCollection,
81    ) -> Self {
82        Self::OverloadResolution(OverloadResolution::function_overload_resolution_failed(
83            func_name, arg_types,
84        ))
85    }
86
87    /// Binary operator type not matches overloads
88    #[tracing::instrument()]
89    pub fn binary_operator_overload_resolution_failed(
90        operator_def: &OperatorDefinition,
91        left_type: &TypeReference,
92        right_type: &TypeReference,
93    ) -> Self {
94        Self::OverloadResolution(
95            OverloadResolution::binary_operator_overload_resolution_failed(
96                operator_def,
97                left_type,
98                right_type,
99            ),
100        )
101    }
102
103    /// Unarry operator type not matches overloads
104    #[tracing::instrument()]
105    pub fn unary_operator_overload_resolution_failed(
106        operator_def: &OperatorDefinition,
107        arg_type: &TypeReference,
108    ) -> Self {
109        Self::OverloadResolution(
110            OverloadResolution::unary_operator_overload_resolution_failed(operator_def, arg_type),
111        )
112    }
113
114    /// Binary operaot type overloads ambiguous
115    #[tracing::instrument()]
116    pub fn binary_operator_overload_ambiguous(
117        operator_def: &OperatorDefinition,
118        left_type: &TypeReference,
119        right_type: &TypeReference,
120    ) -> Self {
121        Self::OverloadResolution(OverloadResolution::binary_operator_overload_ambiguous(
122            operator_def,
123            left_type,
124            right_type,
125        ))
126    }
127
128    /// Unarray operator type ambiguous
129    #[tracing::instrument()]
130    pub fn unary_operator_overload_ambiguous(
131        operator_def: &OperatorDefinition,
132        arg_type: &TypeReference,
133    ) -> Self {
134        Self::OverloadResolution(OverloadResolution::unary_operator_overload_ambiguous(
135            operator_def,
136            arg_type,
137        ))
138    }
139}