@@ -175,22 +175,75 @@ pub fn get_reference_from_var_name<'a>(
175175}
176176
177177pub fn get_constant_from_var_name < ' a > (
178- var_name : & ' static str ,
178+ var_name : & str ,
179179 identifiers : & ' a HashMap < String , Identifier > ,
180180 accessible_scopes : & [ String ] ,
181181) -> Result < & ' a Felt252 , HintError > {
182- accessible_scopes
183- . iter ( )
184- . rev ( )
185- . find_map ( |scope| {
186- let identifier = identifiers. get ( & format ! ( "{}.{}" , scope, var_name) ) ?;
187- if identifier. type_ . as_ref ( ) ? == "const" {
188- identifier. value . as_ref ( )
189- } else {
190- None
182+ for scope in accessible_scopes. iter ( ) . rev ( ) {
183+ let full_path = format ! ( "{}.{}" , scope, var_name) ;
184+ let identifier = identifiers. get ( & full_path) ;
185+
186+ let Some ( identifier) = identifier else {
187+ continue ;
188+ } ;
189+
190+ let identifier_type = identifier
191+ . type_
192+ . as_ref ( )
193+ . ok_or_else ( || HintError :: MissingConstant ( Box :: new ( var_name. to_string ( ) ) ) ) ?;
194+
195+ match & identifier_type[ ..] {
196+ "const" => {
197+ return identifier
198+ . value
199+ . as_ref ( )
200+ . ok_or_else ( || HintError :: MissingConstant ( Box :: new ( var_name. to_string ( ) ) ) )
201+ }
202+ "alias" => {
203+ let destination = identifier
204+ . destination
205+ . as_ref ( )
206+ . ok_or_else ( || HintError :: MissingConstant ( Box :: new ( var_name. to_string ( ) ) ) ) ?;
207+
208+ return get_constant_from_alias ( destination, identifiers) ;
191209 }
192- } )
193- . ok_or_else ( || HintError :: MissingConstant ( Box :: new ( var_name) ) )
210+ _ => return Err ( HintError :: MissingConstant ( Box :: new ( var_name. to_string ( ) ) ) ) ,
211+ }
212+ }
213+
214+ Err ( HintError :: MissingConstant ( Box :: new ( var_name. to_string ( ) ) ) )
215+ }
216+
217+ pub fn get_constant_from_alias < ' a > (
218+ destination : & str ,
219+ identifiers : & ' a HashMap < String , Identifier > ,
220+ ) -> Result < & ' a Felt252 , HintError > {
221+ let identifier = identifiers
222+ . get ( destination)
223+ . ok_or_else ( || HintError :: MissingConstant ( Box :: new ( destination. to_string ( ) ) ) ) ?;
224+
225+ let identifier_type = identifier
226+ . type_
227+ . as_ref ( )
228+ . ok_or_else ( || HintError :: MissingConstant ( Box :: new ( destination. to_string ( ) ) ) ) ?;
229+
230+ match & identifier_type[ ..] {
231+ "const" => identifier
232+ . value
233+ . as_ref ( )
234+ . ok_or_else ( || HintError :: MissingConstant ( Box :: new ( destination. to_string ( ) ) ) ) ,
235+ "alias" => {
236+ let destination = identifier
237+ . destination
238+ . as_ref ( )
239+ . ok_or_else ( || HintError :: MissingConstant ( Box :: new ( destination. to_string ( ) ) ) ) ?;
240+
241+ get_constant_from_alias ( destination, identifiers)
242+ }
243+ _ => Err ( HintError :: MissingConstant ( Box :: new (
244+ destination. to_string ( ) ,
245+ ) ) ) ,
246+ }
194247}
195248
196249#[ cfg( test) ]
0 commit comments