11use iter_extended:: vecmap;
2- use noirc_errors:: { Location , Span } ;
2+ use noirc_errors:: Span ;
33
44use crate :: hir_def:: expr:: { HirExpression , HirIdent , HirLiteral } ;
55use crate :: hir_def:: stmt:: {
@@ -195,41 +195,43 @@ impl<'interner> TypeChecker<'interner> {
195195
196196 ( typ. clone ( ) , HirLValue :: Ident ( ident. clone ( ) , typ) , mutable)
197197 }
198- HirLValue :: MemberAccess { object, field_name, .. } => {
198+ HirLValue :: MemberAccess { object, field_name, location , .. } => {
199199 let ( lhs_type, object, mut mutable) = self . check_lvalue ( object, assign_span) ;
200200 let mut object = Box :: new ( object) ;
201- let span = field_name. span ( ) ;
202201 let field_name = field_name. clone ( ) ;
203202
204203 let object_ref = & mut object;
205204 let mutable_ref = & mut mutable;
205+ let location = * location;
206206
207207 let dereference_lhs = move |_: & mut Self , _, element_type| {
208208 // We must create a temporary value first to move out of object_ref before
209209 // we eventually reassign to it.
210210 let id = DefinitionId :: dummy_id ( ) ;
211- let location = Location :: new ( span, fm:: FileId :: dummy ( ) ) ;
212211 let ident = HirIdent :: non_trait_method ( id, location) ;
213212 let tmp_value = HirLValue :: Ident ( ident, Type :: Error ) ;
214213
215214 let lvalue = std:: mem:: replace ( object_ref, Box :: new ( tmp_value) ) ;
216- * object_ref = Box :: new ( HirLValue :: Dereference { lvalue, element_type } ) ;
215+ * object_ref =
216+ Box :: new ( HirLValue :: Dereference { lvalue, element_type, location } ) ;
217217 * mutable_ref = true ;
218218 } ;
219219
220220 let name = & field_name. 0 . contents ;
221221 let ( object_type, field_index) = self
222- . check_field_access ( & lhs_type, name, span, Some ( dereference_lhs) )
222+ . check_field_access ( & lhs_type, name, field_name . span ( ) , Some ( dereference_lhs) )
223223 . unwrap_or ( ( Type :: Error , 0 ) ) ;
224224
225225 let field_index = Some ( field_index) ;
226226 let typ = object_type. clone ( ) ;
227- let lvalue = HirLValue :: MemberAccess { object, field_name, field_index, typ } ;
227+ let lvalue =
228+ HirLValue :: MemberAccess { object, field_name, field_index, typ, location } ;
228229 ( object_type, lvalue, mutable)
229230 }
230- HirLValue :: Index { array, index, .. } => {
231+ HirLValue :: Index { array, index, location , .. } => {
231232 let index_type = self . check_expression ( index) ;
232233 let expr_span = self . interner . expr_span ( index) ;
234+ let location = * location;
233235
234236 index_type. unify (
235237 & Type :: polymorphic_integer_or_field ( self . interner ) ,
@@ -248,7 +250,8 @@ impl<'interner> TypeChecker<'interner> {
248250 // as needed to unwrap any &mut wrappers.
249251 while let Type :: MutableReference ( element) = lvalue_type. follow_bindings ( ) {
250252 let element_type = element. as_ref ( ) . clone ( ) ;
251- lvalue = HirLValue :: Dereference { lvalue : Box :: new ( lvalue) , element_type } ;
253+ lvalue =
254+ HirLValue :: Dereference { lvalue : Box :: new ( lvalue) , element_type, location } ;
252255 lvalue_type = * element;
253256 // We know this value to be mutable now since we found an `&mut`
254257 mutable = true ;
@@ -275,11 +278,12 @@ impl<'interner> TypeChecker<'interner> {
275278 } ;
276279
277280 let array = Box :: new ( lvalue) ;
278- ( typ. clone ( ) , HirLValue :: Index { array, index : * index, typ } , mutable)
281+ ( typ. clone ( ) , HirLValue :: Index { array, index : * index, typ, location } , mutable)
279282 }
280- HirLValue :: Dereference { lvalue, element_type : _ } => {
283+ HirLValue :: Dereference { lvalue, element_type : _, location } => {
281284 let ( reference_type, lvalue, _) = self . check_lvalue ( lvalue, assign_span) ;
282285 let lvalue = Box :: new ( lvalue) ;
286+ let location = * location;
283287
284288 let element_type = Type :: type_variable ( self . interner . next_type_variable_id ( ) ) ;
285289 let expected_type = Type :: MutableReference ( Box :: new ( element_type. clone ( ) ) ) ;
@@ -291,7 +295,11 @@ impl<'interner> TypeChecker<'interner> {
291295 } ) ;
292296
293297 // Dereferences are always mutable since we already type checked against a &mut T
294- ( element_type. clone ( ) , HirLValue :: Dereference { lvalue, element_type } , true )
298+ (
299+ element_type. clone ( ) ,
300+ HirLValue :: Dereference { lvalue, element_type, location } ,
301+ true ,
302+ )
295303 }
296304 }
297305 }
0 commit comments