sway_core/semantic_analysis/
symbol_resolve.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
use sway_error::handler::Handler;

use crate::{
    ast_elements::binding::SymbolResolveTypeBinding,
    decl_engine::{parsed_engine::ParsedDeclEngineReplace, parsed_id::ParsedDeclId},
    language::{
        parsed::{
            AbiDeclaration, AstNode, AstNodeContent, CodeBlock, ConfigurableDeclaration,
            ConstantDeclaration, Declaration, EnumDeclaration, EnumVariant, Expression,
            ExpressionKind, FunctionDeclaration, FunctionParameter, ImplItem, ImplSelfOrTrait,
            ParseModule, ParseProgram, ReassignmentTarget, Scrutinee, StorageDeclaration,
            StorageEntry, StructDeclaration, StructExpressionField, StructField,
            StructScrutineeField, Supertrait, TraitDeclaration, TraitFn, TraitItem,
            TraitTypeDeclaration, TypeAliasDeclaration, VariableDeclaration,
        },
        CallPath, CallPathTree, ResolvedCallPath,
    },
    TraitConstraint, TypeArgument, TypeBinding, TypeParameter,
};

use super::symbol_resolve_context::SymbolResolveContext;

pub trait ResolveSymbols {
    fn resolve_symbols(&mut self, handler: &Handler, ctx: SymbolResolveContext);
}

impl ResolveSymbols for ParseProgram {
    fn resolve_symbols(&mut self, handler: &Handler, mut ctx: SymbolResolveContext) {
        let ParseProgram { root, .. } = self;
        root.resolve_symbols(handler, ctx.by_ref());
    }
}

impl ResolveSymbols for ParseModule {
    fn resolve_symbols(&mut self, handler: &Handler, mut ctx: SymbolResolveContext) {
        let ParseModule {
            submodules,
            tree,
            module_eval_order,
            attributes: _,
            span: _,
            hash: _,
            ..
        } = self;

        // Analyze submodules first in order of evaluation previously computed by the dependency graph.
        module_eval_order.iter().for_each(|eval_mod_name| {
            let (_name, submodule) = submodules
                .iter_mut()
                .find(|(submod_name, _submodule)| eval_mod_name == submod_name)
                .unwrap();
            submodule.module.resolve_symbols(handler, ctx.by_ref());
        });

        tree.root_nodes
            .iter_mut()
            .for_each(|node| node.resolve_symbols(handler, ctx.by_ref()))
    }
}

impl ResolveSymbols for AstNode {
    fn resolve_symbols(&mut self, handler: &Handler, ctx: SymbolResolveContext) {
        match &mut self.content {
            AstNodeContent::UseStatement(_) => {}
            AstNodeContent::Declaration(decl) => decl.resolve_symbols(handler, ctx),
            AstNodeContent::Expression(expr) => expr.resolve_symbols(handler, ctx),
            AstNodeContent::IncludeStatement(_) => {}
            AstNodeContent::Error(_, _) => {}
        }
    }
}

impl ResolveSymbols for Declaration {
    fn resolve_symbols(&mut self, handler: &Handler, ctx: SymbolResolveContext) {
        match self {
            Declaration::VariableDeclaration(decl_id) => decl_id.resolve_symbols(handler, ctx),
            Declaration::FunctionDeclaration(decl_id) => decl_id.resolve_symbols(handler, ctx),
            Declaration::TraitDeclaration(decl_id) => decl_id.resolve_symbols(handler, ctx),
            Declaration::StructDeclaration(decl_id) => decl_id.resolve_symbols(handler, ctx),
            Declaration::EnumDeclaration(decl_id) => decl_id.resolve_symbols(handler, ctx),
            Declaration::EnumVariantDeclaration(_decl) => unreachable!(),
            Declaration::ImplSelfOrTrait(decl_id) => decl_id.resolve_symbols(handler, ctx),
            Declaration::AbiDeclaration(decl_id) => decl_id.resolve_symbols(handler, ctx),
            Declaration::ConstantDeclaration(decl_id) => decl_id.resolve_symbols(handler, ctx),
            Declaration::StorageDeclaration(decl_id) => decl_id.resolve_symbols(handler, ctx),
            Declaration::TypeAliasDeclaration(decl_id) => decl_id.resolve_symbols(handler, ctx),
            Declaration::TraitTypeDeclaration(decl_id) => decl_id.resolve_symbols(handler, ctx),
            Declaration::TraitFnDeclaration(decl_id) => decl_id.resolve_symbols(handler, ctx),
            Declaration::ConfigurableDeclaration(decl_id) => decl_id.resolve_symbols(handler, ctx),
        }
    }
}

impl ResolveSymbols for ParsedDeclId<VariableDeclaration> {
    fn resolve_symbols(&mut self, handler: &Handler, ctx: SymbolResolveContext) {
        let pe = ctx.engines().pe();
        let mut var_decl = pe.get_variable(self).as_ref().clone();
        var_decl.body.resolve_symbols(handler, ctx);
        pe.replace(*self, var_decl);
    }
}

impl ResolveSymbols for ParsedDeclId<FunctionDeclaration> {
    fn resolve_symbols(&mut self, handler: &Handler, ctx: SymbolResolveContext) {
        let pe = ctx.engines().pe();
        let mut fn_decl = pe.get_function(self).as_ref().clone();
        fn_decl.body.resolve_symbols(handler, ctx);
        pe.replace(*self, fn_decl);
    }
}

impl ResolveSymbols for ParsedDeclId<TraitDeclaration> {
    fn resolve_symbols(&mut self, handler: &Handler, ctx: SymbolResolveContext) {
        let pe = ctx.engines().pe();
        let mut trait_decl = ctx.engines().pe().get_trait(self).as_ref().clone();
        trait_decl.resolve_symbols(handler, ctx);
        pe.replace(*self, trait_decl);
    }
}

impl ResolveSymbols for ParsedDeclId<StructDeclaration> {
    fn resolve_symbols(&mut self, handler: &Handler, ctx: SymbolResolveContext) {
        let pe = ctx.engines().pe();
        let mut struct_decl = ctx.engines().pe().get_struct(self).as_ref().clone();
        struct_decl.resolve_symbols(handler, ctx);
        pe.replace(*self, struct_decl);
    }
}

impl ResolveSymbols for ParsedDeclId<EnumDeclaration> {
    fn resolve_symbols(&mut self, handler: &Handler, ctx: SymbolResolveContext) {
        let pe = ctx.engines().pe();
        let mut enum_decl = ctx.engines().pe().get_enum(self).as_ref().clone();
        enum_decl.resolve_symbols(handler, ctx);
        pe.replace(*self, enum_decl);
    }
}

impl ResolveSymbols for ParsedDeclId<ConfigurableDeclaration> {
    fn resolve_symbols(&mut self, handler: &Handler, ctx: SymbolResolveContext) {
        let pe = ctx.engines().pe();
        let mut configurable_decl = ctx.engines().pe().get_configurable(self).as_ref().clone();
        configurable_decl.resolve_symbols(handler, ctx);
        pe.replace(*self, configurable_decl);
    }
}

impl ResolveSymbols for ParsedDeclId<ConstantDeclaration> {
    fn resolve_symbols(&mut self, handler: &Handler, ctx: SymbolResolveContext) {
        let pe = ctx.engines().pe();
        let mut constant_decl = ctx.engines().pe().get_constant(self).as_ref().clone();
        constant_decl.resolve_symbols(handler, ctx);
        pe.replace(*self, constant_decl);
    }
}

impl ResolveSymbols for ParsedDeclId<TraitTypeDeclaration> {
    fn resolve_symbols(&mut self, handler: &Handler, ctx: SymbolResolveContext) {
        let pe = ctx.engines().pe();
        let mut trait_type_decl = ctx.engines().pe().get_trait_type(self).as_ref().clone();
        trait_type_decl.resolve_symbols(handler, ctx);
        pe.replace(*self, trait_type_decl);
    }
}

impl ResolveSymbols for ParsedDeclId<TraitFn> {
    fn resolve_symbols(&mut self, handler: &Handler, ctx: SymbolResolveContext) {
        let pe = ctx.engines().pe();
        let mut trait_fn_decl = ctx.engines().pe().get_trait_fn(self).as_ref().clone();
        trait_fn_decl.resolve_symbols(handler, ctx);
        pe.replace(*self, trait_fn_decl);
    }
}

impl ResolveSymbols for ParsedDeclId<ImplSelfOrTrait> {
    fn resolve_symbols(&mut self, handler: &Handler, ctx: SymbolResolveContext) {
        let pe = ctx.engines().pe();
        let mut impl_self_or_trait = ctx
            .engines()
            .pe()
            .get_impl_self_or_trait(self)
            .as_ref()
            .clone();
        impl_self_or_trait.resolve_symbols(handler, ctx);
        pe.replace(*self, impl_self_or_trait);
    }
}

impl ResolveSymbols for ParsedDeclId<AbiDeclaration> {
    fn resolve_symbols(&mut self, handler: &Handler, ctx: SymbolResolveContext) {
        let pe = ctx.engines().pe();
        let mut abi_decl = ctx.engines().pe().get_abi(self).as_ref().clone();
        abi_decl.resolve_symbols(handler, ctx);
        pe.replace(*self, abi_decl);
    }
}

impl ResolveSymbols for ParsedDeclId<StorageDeclaration> {
    fn resolve_symbols(&mut self, handler: &Handler, ctx: SymbolResolveContext) {
        let pe = ctx.engines().pe();
        let mut storage_decl = ctx.engines().pe().get_storage(self).as_ref().clone();
        storage_decl.resolve_symbols(handler, ctx);
        pe.replace(*self, storage_decl);
    }
}

impl ResolveSymbols for ParsedDeclId<TypeAliasDeclaration> {
    fn resolve_symbols(&mut self, handler: &Handler, ctx: SymbolResolveContext) {
        let pe = ctx.engines().pe();
        let mut type_alias = ctx.engines().pe().get_type_alias(self).as_ref().clone();
        type_alias.resolve_symbols(handler, ctx);
        pe.replace(*self, type_alias);
    }
}

impl ResolveSymbols for ConfigurableDeclaration {
    fn resolve_symbols(&mut self, handler: &Handler, mut ctx: SymbolResolveContext) {
        self.type_ascription.resolve_symbols(handler, ctx.by_ref());
        if let Some(value) = self.value.as_mut() {
            value.resolve_symbols(handler, ctx.by_ref())
        }
    }
}

impl ResolveSymbols for ConstantDeclaration {
    fn resolve_symbols(&mut self, handler: &Handler, mut ctx: SymbolResolveContext) {
        self.type_ascription.resolve_symbols(handler, ctx.by_ref());
        if let Some(value) = self.value.as_mut() {
            value.resolve_symbols(handler, ctx.by_ref())
        }
    }
}

impl ResolveSymbols for StructDeclaration {
    fn resolve_symbols(&mut self, handler: &Handler, mut ctx: SymbolResolveContext) {
        self.type_parameters
            .iter_mut()
            .for_each(|tp| tp.resolve_symbols(handler, ctx.by_ref()));
        self.fields
            .iter_mut()
            .for_each(|f| f.resolve_symbols(handler, ctx.by_ref()));
    }
}

impl ResolveSymbols for StructField {
    fn resolve_symbols(&mut self, handler: &Handler, ctx: SymbolResolveContext) {
        self.type_argument.resolve_symbols(handler, ctx);
    }
}

impl ResolveSymbols for EnumDeclaration {
    fn resolve_symbols(&mut self, handler: &Handler, mut ctx: SymbolResolveContext) {
        self.type_parameters
            .iter_mut()
            .for_each(|tp| tp.resolve_symbols(handler, ctx.by_ref()));
        self.variants
            .iter_mut()
            .for_each(|f| f.resolve_symbols(handler, ctx.by_ref()));
    }
}

impl ResolveSymbols for EnumVariant {
    fn resolve_symbols(&mut self, handler: &Handler, ctx: SymbolResolveContext) {
        self.type_argument.resolve_symbols(handler, ctx);
    }
}

impl ResolveSymbols for TraitDeclaration {
    fn resolve_symbols(&mut self, handler: &Handler, mut ctx: SymbolResolveContext) {
        self.supertraits
            .iter_mut()
            .for_each(|st| st.resolve_symbols(handler, ctx.by_ref()));
        self.interface_surface
            .iter_mut()
            .for_each(|item| item.resolve_symbols(handler, ctx.by_ref()));
        self.methods
            .iter_mut()
            .for_each(|m| m.resolve_symbols(handler, ctx.by_ref()));
    }
}

impl ResolveSymbols for AbiDeclaration {
    fn resolve_symbols(&mut self, handler: &Handler, mut ctx: SymbolResolveContext) {
        self.supertraits
            .iter_mut()
            .for_each(|st| st.resolve_symbols(handler, ctx.by_ref()));
        self.interface_surface
            .iter_mut()
            .for_each(|item| item.resolve_symbols(handler, ctx.by_ref()));
        self.methods
            .iter_mut()
            .for_each(|m| m.resolve_symbols(handler, ctx.by_ref()));
    }
}

impl ResolveSymbols for TraitItem {
    fn resolve_symbols(&mut self, handler: &Handler, mut ctx: SymbolResolveContext) {
        match self {
            TraitItem::TraitFn(ref mut id) => id.resolve_symbols(handler, ctx.by_ref()),
            TraitItem::Constant(ref mut id) => id.resolve_symbols(handler, ctx.by_ref()),
            TraitItem::Type(ref mut id) => id.resolve_symbols(handler, ctx.by_ref()),
            TraitItem::Error(_, _) => {}
        }
    }
}

impl ResolveSymbols for TraitFn {
    fn resolve_symbols(&mut self, handler: &Handler, mut ctx: SymbolResolveContext) {
        self.parameters
            .iter_mut()
            .for_each(|f| f.resolve_symbols(handler, ctx.by_ref()));
        self.return_type.resolve_symbols(handler, ctx.by_ref());
    }
}

impl ResolveSymbols for Supertrait {
    fn resolve_symbols(&mut self, handler: &Handler, mut ctx: SymbolResolveContext) {
        self.name.resolve_symbols(handler, ctx.by_ref());
    }
}

impl ResolveSymbols for FunctionParameter {
    fn resolve_symbols(&mut self, handler: &Handler, mut ctx: SymbolResolveContext) {
        self.type_argument.resolve_symbols(handler, ctx.by_ref());
    }
}

impl ResolveSymbols for ImplSelfOrTrait {
    fn resolve_symbols(&mut self, handler: &Handler, mut ctx: SymbolResolveContext) {
        self.impl_type_parameters
            .iter_mut()
            .for_each(|f| f.resolve_symbols(handler, ctx.by_ref()));
        self.trait_name.resolve_symbols(handler, ctx.by_ref());
        self.trait_type_arguments
            .iter_mut()
            .for_each(|tp| tp.resolve_symbols(handler, ctx.by_ref()));
        self.implementing_for.resolve_symbols(handler, ctx.by_ref());
        self.items
            .iter_mut()
            .for_each(|tp| tp.resolve_symbols(handler, ctx.by_ref()));
    }
}

impl ResolveSymbols for ImplItem {
    fn resolve_symbols(&mut self, handler: &Handler, ctx: SymbolResolveContext) {
        match self {
            ImplItem::Fn(decl_id) => decl_id.resolve_symbols(handler, ctx),
            ImplItem::Constant(decl_id) => decl_id.resolve_symbols(handler, ctx),
            ImplItem::Type(decl_id) => decl_id.resolve_symbols(handler, ctx),
        }
    }
}

impl ResolveSymbols for TraitTypeDeclaration {
    fn resolve_symbols(&mut self, handler: &Handler, ctx: SymbolResolveContext) {
        if let Some(ty) = self.ty_opt.as_mut() {
            ty.resolve_symbols(handler, ctx)
        }
    }
}

impl ResolveSymbols for StorageDeclaration {
    fn resolve_symbols(&mut self, handler: &Handler, mut ctx: SymbolResolveContext) {
        self.entries
            .iter_mut()
            .for_each(|e| e.resolve_symbols(handler, ctx.by_ref()));
    }
}

impl ResolveSymbols for StorageEntry {
    fn resolve_symbols(&mut self, handler: &Handler, mut ctx: SymbolResolveContext) {
        match self {
            StorageEntry::Namespace(ref mut ns) => {
                ns.entries
                    .iter_mut()
                    .for_each(|e| e.resolve_symbols(handler, ctx.by_ref()));
            }
            StorageEntry::Field(ref mut f) => {
                f.type_argument.resolve_symbols(handler, ctx.by_ref());
                f.initializer.resolve_symbols(handler, ctx.by_ref());
            }
        }
    }
}

impl ResolveSymbols for TypeAliasDeclaration {
    fn resolve_symbols(&mut self, handler: &Handler, ctx: SymbolResolveContext) {
        self.ty.resolve_symbols(handler, ctx)
    }
}

impl ResolveSymbols for TypeArgument {
    fn resolve_symbols(&mut self, handler: &Handler, ctx: SymbolResolveContext) {
        if let Some(call_path) = self.call_path_tree.as_mut() {
            call_path.resolve_symbols(handler, ctx);
        }
    }
}

impl ResolveSymbols for TypeParameter {
    fn resolve_symbols(&mut self, handler: &Handler, mut ctx: SymbolResolveContext) {
        self.trait_constraints
            .iter_mut()
            .for_each(|tc| tc.resolve_symbols(handler, ctx.by_ref()));
    }
}

impl ResolveSymbols for TraitConstraint {
    fn resolve_symbols(&mut self, handler: &Handler, mut ctx: SymbolResolveContext) {
        self.trait_name.resolve_symbols(handler, ctx.by_ref());
        self.type_arguments
            .iter_mut()
            .for_each(|tc| tc.resolve_symbols(handler, ctx.by_ref()));
    }
}

impl ResolveSymbols for CallPath {
    fn resolve_symbols(&mut self, _handler: &Handler, _ctx: SymbolResolveContext) {}
}

impl ResolveSymbols for CallPathTree {
    fn resolve_symbols(&mut self, _handler: &Handler, _ctx: SymbolResolveContext) {}
}

impl ResolveSymbols for CodeBlock {
    fn resolve_symbols(&mut self, handler: &Handler, mut ctx: SymbolResolveContext) {
        for expr in self.contents.iter_mut() {
            expr.resolve_symbols(handler, ctx.by_ref())
        }
    }
}

impl ResolveSymbols for StructExpressionField {
    fn resolve_symbols(&mut self, handler: &Handler, ctx: SymbolResolveContext) {
        self.value.resolve_symbols(handler, ctx);
    }
}

impl ResolveSymbols for Scrutinee {
    fn resolve_symbols(&mut self, handler: &Handler, mut ctx: SymbolResolveContext) {
        match self {
            Scrutinee::Or {
                ref mut elems,
                span: _,
            } => elems
                .iter_mut()
                .for_each(|e| e.resolve_symbols(handler, ctx.by_ref())),
            Scrutinee::CatchAll { .. } => {}
            Scrutinee::Literal { .. } => {}
            Scrutinee::Variable { .. } => {}
            Scrutinee::AmbiguousSingleIdent(_) => {}
            Scrutinee::StructScrutinee {
                struct_name,
                fields,
                span: _,
            } => {
                struct_name.resolve_symbols(handler, ctx.by_ref());
                fields
                    .iter_mut()
                    .for_each(|f| f.resolve_symbols(handler, ctx.by_ref()))
            }
            Scrutinee::EnumScrutinee {
                call_path,
                value,
                span: _,
            } => {
                call_path.resolve_symbols(handler, ctx.by_ref());
                value.resolve_symbols(handler, ctx.by_ref());
            }
            Scrutinee::Tuple { elems, span: _ } => {
                elems
                    .iter_mut()
                    .for_each(|s| s.resolve_symbols(handler, ctx.by_ref()));
            }
            Scrutinee::Error { .. } => {}
        }
    }
}

impl ResolveSymbols for StructScrutineeField {
    fn resolve_symbols(&mut self, handler: &Handler, mut ctx: SymbolResolveContext) {
        match self {
            StructScrutineeField::Rest { .. } => {}
            StructScrutineeField::Field {
                field: _,
                scrutinee,
                span: _,
            } => {
                if let Some(scrutinee) = scrutinee.as_mut() {
                    scrutinee.resolve_symbols(handler, ctx.by_ref());
                }
            }
        }
    }
}

impl ResolveSymbols for Expression {
    fn resolve_symbols(&mut self, handler: &Handler, ctx: SymbolResolveContext) {
        self.kind.resolve_symbols(handler, ctx);
    }
}

impl ResolveSymbols for ExpressionKind {
    fn resolve_symbols(&mut self, handler: &Handler, mut ctx: SymbolResolveContext) {
        match self {
            ExpressionKind::Error(_, _) => {}
            ExpressionKind::Literal(_) => {}
            ExpressionKind::AmbiguousPathExpression(_) => {}
            ExpressionKind::FunctionApplication(expr) => {
                let result = SymbolResolveTypeBinding::resolve_symbol(
                    &mut expr.call_path_binding,
                    &Handler::default(),
                    ctx.by_ref(),
                );
                if let Ok(result) = result {
                    expr.resolved_call_path_binding = Some(TypeBinding::<
                        ResolvedCallPath<ParsedDeclId<FunctionDeclaration>>,
                    > {
                        inner: ResolvedCallPath {
                            decl: result,
                            unresolved_call_path: expr.call_path_binding.inner.clone(),
                        },
                        span: expr.call_path_binding.span.clone(),
                        type_arguments: expr.call_path_binding.type_arguments.clone(),
                    });
                }
                expr.arguments
                    .iter_mut()
                    .for_each(|a| a.resolve_symbols(handler, ctx.by_ref()))
            }
            ExpressionKind::LazyOperator(expr) => {
                expr.lhs.resolve_symbols(handler, ctx.by_ref());
                expr.rhs.resolve_symbols(handler, ctx.by_ref());
            }
            ExpressionKind::AmbiguousVariableExpression(_) => {}
            ExpressionKind::Variable(_) => {}
            ExpressionKind::Tuple(exprs) => {
                exprs
                    .iter_mut()
                    .for_each(|expr| expr.resolve_symbols(handler, ctx.by_ref()));
            }
            ExpressionKind::TupleIndex(expr) => {
                expr.prefix.resolve_symbols(handler, ctx.by_ref());
            }
            ExpressionKind::Array(expr) => expr
                .contents
                .iter_mut()
                .for_each(|e| e.resolve_symbols(handler, ctx.by_ref())),
            ExpressionKind::Struct(expr) => {
                expr.call_path_binding
                    .resolve_symbols(handler, ctx.by_ref());
                let result = SymbolResolveTypeBinding::resolve_symbol(
                    &mut expr.call_path_binding,
                    &Handler::default(),
                    ctx.by_ref(),
                );
                if let Ok(result) = result {
                    expr.resolved_call_path_binding = Some(TypeBinding::<
                        ResolvedCallPath<ParsedDeclId<StructDeclaration>>,
                    > {
                        inner: ResolvedCallPath {
                            decl: result,
                            unresolved_call_path: expr.call_path_binding.inner.clone(),
                        },
                        span: expr.call_path_binding.span.clone(),
                        type_arguments: expr.call_path_binding.type_arguments.clone(),
                    });
                }
            }
            ExpressionKind::CodeBlock(block) => {
                block
                    .contents
                    .iter_mut()
                    .for_each(|node| node.resolve_symbols(handler, ctx.by_ref()));
            }
            ExpressionKind::If(expr) => {
                expr.condition.resolve_symbols(handler, ctx.by_ref());
                expr.then.resolve_symbols(handler, ctx.by_ref());
                if let Some(r#else) = expr.r#else.as_mut() {
                    r#else.resolve_symbols(handler, ctx.by_ref());
                }
            }
            ExpressionKind::Match(expr) => {
                expr.value.resolve_symbols(handler, ctx.by_ref());
                expr.branches.iter_mut().for_each(|branch| {
                    branch.scrutinee.resolve_symbols(handler, ctx.by_ref());
                    branch.result.resolve_symbols(handler, ctx.by_ref());
                });
            }
            ExpressionKind::Asm(asm_expr) => asm_expr.registers.iter_mut().for_each(|reg| {
                if let Some(initializer) = reg.initializer.as_mut() {
                    initializer.resolve_symbols(handler, ctx.by_ref());
                }
            }),
            ExpressionKind::MethodApplication(expr) => {
                expr.method_name_binding
                    .resolve_symbols(handler, ctx.by_ref());
                expr.contract_call_params
                    .iter_mut()
                    .for_each(|field| field.resolve_symbols(handler, ctx.by_ref()));
                expr.arguments
                    .iter_mut()
                    .for_each(|arg| arg.resolve_symbols(handler, ctx.by_ref()));
            }
            ExpressionKind::Subfield(expr) => expr.prefix.resolve_symbols(handler, ctx),
            ExpressionKind::DelineatedPath(expr) => {
                expr.call_path_binding.resolve_symbols(handler, ctx)
            }
            ExpressionKind::AbiCast(expr) => {
                expr.abi_name.resolve_symbols(handler, ctx.by_ref());
                expr.address.resolve_symbols(handler, ctx.by_ref());
            }
            ExpressionKind::ArrayIndex(expr) => {
                expr.index.resolve_symbols(handler, ctx.by_ref());
                expr.prefix.resolve_symbols(handler, ctx.by_ref());
            }
            ExpressionKind::StorageAccess(_expr) => {}
            ExpressionKind::IntrinsicFunction(expr) => {
                expr.arguments
                    .iter_mut()
                    .for_each(|arg| arg.resolve_symbols(handler, ctx.by_ref()));
                expr.kind_binding.resolve_symbols(handler, ctx);
            }
            ExpressionKind::WhileLoop(expr) => {
                expr.condition.resolve_symbols(handler, ctx.by_ref());
                expr.body.resolve_symbols(handler, ctx.by_ref());
            }
            ExpressionKind::ForLoop(expr) => expr.desugared.resolve_symbols(handler, ctx.by_ref()),
            ExpressionKind::Break => {}
            ExpressionKind::Continue => {}
            ExpressionKind::Reassignment(expr) => {
                match &mut expr.lhs {
                    ReassignmentTarget::ElementAccess(expr) => {
                        expr.resolve_symbols(handler, ctx.by_ref())
                    }
                    ReassignmentTarget::Deref(expr) => expr.resolve_symbols(handler, ctx.by_ref()),
                };
                expr.rhs.resolve_symbols(handler, ctx.by_ref());
            }
            ExpressionKind::ImplicitReturn(expr) => expr.resolve_symbols(handler, ctx),
            ExpressionKind::Return(expr) => expr.resolve_symbols(handler, ctx.by_ref()),
            ExpressionKind::Ref(expr) => expr.value.resolve_symbols(handler, ctx.by_ref()),
            ExpressionKind::Deref(expr) => expr.resolve_symbols(handler, ctx.by_ref()),
        }
    }
}