@@ -5,7 +5,7 @@ use astoir_mir::{blocks::refer::MIRBlockReference, builder::{build_comp_eq, buil
55use compiler_typing:: { SizedType , raw:: RawType , tree:: Type } ;
66use diagnostics:: { DiagnosticResult , DiagnosticSpanOrigin , builders:: { make_req_type_kind, make_type_not_partof} } ;
77
8- use crate :: { MIRLoweringContext , lower_hir_type, values:: lower_hir_value} ;
8+ use crate :: { MIRLoweringContext , lower_hir_type, values:: lower_hir_value, vars :: lower_hir_variable_reference } ;
99
1010pub fn is_enum_value_of_kind < K : DiagnosticSpanOrigin > ( block : MIRBlockReference , val : BaseMIRValue , enum_entry : RawType , ctx : & mut MIRLoweringContext , origin : & K ) -> DiagnosticResult < MIRIntValue > {
1111 let enum_type = match ctx. mir_ctx . ssa_hints . get_hint ( val. get_ssa_index ( ) ) . get_type ( ) . as_generic_lowered_safe ( origin) ? {
@@ -51,11 +51,26 @@ pub fn is_enum_value_of_kind<K: DiagnosticSpanOrigin>(block: MIRBlockReference,
5151pub fn cast_to_enum_child < K : DiagnosticSpanOrigin > ( block : MIRBlockReference , val : BaseMIRValue , enum_entry : RawType , ctx : & mut MIRLoweringContext , origin : & K ) -> DiagnosticResult < BaseMIRValue > {
5252 let enum_type = match ctx. mir_ctx . ssa_hints . get_hint ( val. get_ssa_index ( ) ) . get_type ( ) . as_generic_lowered_safe ( origin) ? {
5353 RawType :: Enum ( v) => v,
54+ RawType :: LoweredStruct ( _, container) => {
55+ if !container. is_lowered_enum_parent {
56+ return Err ( make_req_type_kind ( origin, & "enum parent" . to_string ( ) ) . into ( ) )
57+ }
58+
59+ container. lowered_enum_parent . unwrap ( )
60+ } ,
61+
5462 _ => return Err ( make_req_type_kind ( origin, & "enum parent" . to_string ( ) ) . into ( ) )
5563 } ;
5664
5765 let enum_entry_container = match & enum_entry {
5866 RawType :: EnumEntry ( v) => v,
67+ RawType :: LoweredStruct ( _, container) => {
68+ if !container. is_lowered_enum_child {
69+ return Err ( make_req_type_kind ( origin, & "enum parent" . to_string ( ) ) . into ( ) )
70+ }
71+
72+ container. lowered_enum_child . as_ref ( ) . unwrap ( )
73+ } ,
5974 _ => return Err ( make_req_type_kind ( origin, & "enum child" . to_string ( ) ) . into ( ) )
6075 } ;
6176
@@ -68,7 +83,7 @@ pub fn cast_to_enum_child<K: DiagnosticSpanOrigin>(block: MIRBlockReference, val
6883
6984pub fn lower_hir_unwrap_cond ( block : MIRBlockReference , node : Box < HIRNode > , ctx : & mut MIRLoweringContext ) -> DiagnosticResult < BaseMIRValue > {
7085 if let HIRNodeKind :: UnwrapCondition { original, new_type, new_var, unsafe_unwrap } = node. kind . clone ( ) {
71- let original = lower_hir_value ( block, original, ctx) ?;
86+ let original = lower_hir_variable_reference ( block, & original, ctx) ?. as_pointer_ref ( ) ? . into ( ) ;
7287 let new_type = lower_hir_type ( ctx, new_type) ?;
7388
7489 let cond;
0 commit comments