11//! The nodes inside of the AstoIR HIR.
22
3- use compiler_typing:: { references:: TypeReference , storage:: { BOOLEAN_TYPE , STATIC_STR } , structs:: RawStructTypeContainer , transmutation:: array:: can_transmute_inner, tree:: Type } ;
3+ use compiler_typing:: { raw :: RawType , references:: TypeReference , storage:: { BOOLEAN_TYPE , STATIC_STR } , structs:: RawStructTypeContainer , transmutation:: array:: can_transmute_inner, tree:: Type } ;
44use compiler_utils:: Position ;
55use diagnostics:: { DiagnosticSpanOrigin , builders:: { make_diff_type, make_diff_type_val} , diagnostic:: { Diagnostic , Span , SpanKind , SpanPosition } , unsure_panic} ;
66use lexer:: toks:: { comp:: ComparingOperator , math:: MathOperator } ;
@@ -51,6 +51,9 @@ pub enum HIRNodeKind {
5151
5252 MathOperation { left : Box < HIRNode > , right : Box < HIRNode > , operation : MathOperator , assignment : bool } ,
5353
54+ UnwrapCondition { original : Box < HIRNode > , new_type : Type , new_var : Option < usize > , unsafe_unwrap : bool } ,
55+ UnwrapValue { original : Box < HIRNode > , new_type : Type , unsafe_unwrap : bool } ,
56+
5457 VariableReference { index : usize , is_static : bool } ,
5558 FunctionReference { index : usize } ,
5659
@@ -172,10 +175,10 @@ impl HIRNode {
172175 }
173176
174177 if let Some ( v) = var_origin {
175- return Err ( make_diff_type ( origin, & "unnamed" . to_string ( ) , & t, & self . get_node_type ( context, curr_ctx) . unwrap ( ) , v) . into ( ) )
178+ return Err ( make_diff_type ( origin, & "unnamed" . to_string ( ) , & t. faulty_lowering_generic ( & context . type_storage ) , & self . get_node_type ( context, curr_ctx) . unwrap ( ) . faulty_lowering_generic ( & context . type_storage ) , v) . into ( ) )
176179 }
177180
178- return Err ( make_diff_type_val ( origin, & t, & self . get_node_type ( context, curr_ctx) . unwrap ( ) ) . into ( ) )
181+ return Err ( make_diff_type_val ( origin, & t. faulty_lowering_generic ( & context . type_storage ) , & self . get_node_type ( context, curr_ctx) . unwrap ( ) . faulty_lowering_generic ( & context . type_storage ) ) . into ( ) )
179182 }
180183
181184 pub fn get_node_type ( & self , context : & HIRContext , curr_ctx : & HIRBranchedContext ) -> Option < Type > {
@@ -196,6 +199,14 @@ impl HIRNode {
196199 return Some ( Type :: Reference ( Box :: new ( val. get_node_type ( context, curr_ctx) . unwrap ( ) ) ) )
197200 }
198201
202+ HIRNodeKind :: UnwrapCondition { .. } => {
203+ return Some ( Type :: Generic ( RawType :: Boolean , vec ! [ ] , vec ! [ ] ) )
204+ } ,
205+
206+ HIRNodeKind :: UnwrapValue { original : _, new_type, unsafe_unwrap : _ } => {
207+ return Some ( new_type. clone ( ) )
208+ } ,
209+
199210 HIRNodeKind :: ArrayIndexAccess { val, index : _ } => {
200211 let t = val. get_node_type ( context, curr_ctx) . unwrap ( ) ;
201212
@@ -212,7 +223,7 @@ impl HIRNode {
212223 None => return None
213224 } ;
214225
215- return Some ( Type :: Generic ( ind , vec ! [ ] , vec ! [ ] ) )
226+ return Some ( Type :: Generic ( RawType :: Boolean , vec ! [ ] , vec ! [ ] ) )
216227 } ,
217228
218229 HIRNodeKind :: ArrayVariableInitializerValue { vals } => return Some ( Type :: Array ( vals. len ( ) , Box :: new ( vals[ 0 ] . get_node_type ( context, curr_ctx) . unwrap ( ) ) ) ) ,
@@ -227,12 +238,7 @@ impl HIRNode {
227238 } ,
228239
229240 HIRNodeKind :: BooleanOperator { .. } | HIRNodeKind :: BooleanCondition { .. } => {
230- let t = match context. type_storage . types . get_index ( BOOLEAN_TYPE ) {
231- Some ( v) => v,
232- None => return None
233- } ;
234-
235- return Some ( Type :: Generic ( t, vec ! [ ] , vec ! [ ] ) )
241+ return Some ( Type :: Generic ( RawType :: Boolean , vec ! [ ] , vec ! [ ] ) )
236242 } ,
237243
238244 HIRNodeKind :: StructVariableInitializerValue { t, fields : _ } => {
0 commit comments