slang_solidity 1.3.2

A modular set of compiler APIs empowering the next generation of Solidity code analysis and developer tooling. Written in Rust and distributed in multiple languages.
Documentation
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
647
648
649
650
651
use std::collections::{HashMap, HashSet, VecDeque};

use super::built_ins::BuiltIn;
use super::types::{Type, TypeId};
use crate::cst::NodeId;

mod definitions;
mod references;
mod scopes;

pub use definitions::Definition;
pub(crate) use definitions::{
    ContractDefinition, FunctionVisibility, ImportDefinition, InterfaceDefinition,
    StateVariableVisibility,
};
pub use references::{Reference, Resolution};
use scopes::ContractScope;
pub(crate) use scopes::{
    EitherIter, FileScope, ParameterDefinition, ParametersScope, Scope, UsingDirective,
};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ScopeId(usize);

//////////////////////////////////////////////////////////////////////////////
// Binder

// TODO: do we want to move tuples (which are not a real Solidity type) as a
// typing variant? That has the additional benefit of not requiring us to
// register every tuple combination.

/// `Typing` represents typing information related to an AST node. If the node
/// happens to be a reference identifier, there is a direct relationship between
/// its `Resolution` and the `Typing`. Otherwise the typing is computed from the
/// node kind and its contents.

#[derive(Clone, Debug)]
pub enum Typing {
    /// The type of the node cannot be resolved at this time (this normally
    /// propagates upwards).
    Unresolved,
    /// Resolved with a corresponding `TypeId` valid in the `TypeRegistry`.
    Resolved(TypeId),
    /// There are multiple possible types that result from the typing of an
    /// `Ambiguous` resolution. Function call overload resolution will select
    /// the appropriate type by matching the types of the arguments and work
    /// backwards to the reference (if any) and fixup the selected definition.
    Undetermined(Vec<TypeId>),
    /// A node which refers to a user defined type by name, eg. the identifier
    /// of a contract. This is not a type that can be translated to the EVM, and
    /// as such is a way to suspend the typing until more information on how
    /// it's used is gathered. Eg. to create a new contract via the new
    /// operator, or construct a struct by using the struct's name in a function
    /// call.
    UserMetaType(NodeId),
    /// Similar to `UserMetaType` above, but refers to the meta type of an
    /// elementary type. A typical use case is explicit casting, which parses as
    /// a function call.
    MetaType(Type),
    /// Used to type the `BuiltIn` resolution when the result is not yet an
    /// actual type representable in the EVM. Eg. the built-in function `addmod`
    /// resolves to `Resolution::BuiltIn(Addmod)` and will type to
    /// `Typing::BuiltIn(Addmod)` which in turn will type to the `uint256` type
    /// when evaluated in the context of a function call.
    BuiltIn(BuiltIn),
    /// A special typing that's used as the result of applying the `new`
    /// operator, and will type to a contract reference when evaluated as a
    /// function call.
    NewExpression(TypeId),
    /// Typing of the `this` keyword. Resolving a member of `this` requires
    /// special lookup rules and it can also type to an address-type equivalent
    /// if used as a value.
    This,
    /// Typing of the `super` keyword. Resolving members requires special lookup
    /// rules.
    Super,
}

impl Typing {
    pub(crate) fn as_type_id(&self) -> Option<TypeId> {
        match self {
            Self::Resolved(type_id) => Some(*type_id),
            _ => None,
        }
    }
}

/// The `Binder` contains binding information for all definitions and references
/// in the `CompilationUnit`, typing information for relevant AST nodes, as well
/// as other semantic information (such as scopes and linearisations).
pub struct Binder {
    /// Index of `Scope` objects. The `ScopeId` is an opaque index into this vector
    scopes: Vec<Scope>,
    /// Scopes (set of definitions contained and relationship to other scopes), indexed by `NodeId`
    scopes_by_node_id: HashMap<NodeId, ScopeId>,
    /// Index of root `FileScope`s for all files in the `CompilationUnit`
    scopes_by_file_id: HashMap<String, ScopeId>,
    /// `UsingDirective` objects registered globally (contract level directives
    /// are stored in the corresponding `ContractScope`)
    global_using_directives: Vec<UsingDirective>,
    /// `Definition` objects (identifier + definiens node), indexed by definiens `NodeId`
    definitions: HashMap<NodeId, Definition>,
    /// Definitions indexed by the `NodeId` of the identifier that names them
    definitions_by_identifier: HashMap<NodeId, NodeId>,
    /// `Reference` objects (identifier + `Resolution`), indexed by identifier `NodeId`
    references: HashMap<NodeId, Reference>,
    /// `Typing` information for each relevant `NodeId` of the AST
    node_typing: HashMap<NodeId, Typing>,
    /// Linearisations, as a vector of definitions, indexed by the
    /// contract/interface definition's `NodeId`
    linearisations: HashMap<NodeId, Vec<NodeId>>,
}

/// This controls visibility filtering and how to use the linearisation when
/// performing a contract scope resolution.
#[derive(Clone, Copy, Eq, PartialEq)]
pub(crate) enum ResolveOptions {
    /// Use all the linearised bases in order for an internal lookup.
    Internal,
    /// Use all the linearised bases for an external lookup.
    External,
    /// Use all bases and only excludes private members in bases types (used for
    /// general qualified member access).
    Qualified,
    /// Starts at `node_id` and proceeds in order for an external lookup.
    This(NodeId),
    /// Starts at the contract _following_ `node_id` (ie. its parent) for an
    /// internal lookup.
    Super(NodeId),
}

impl Binder {
    pub(crate) fn new() -> Self {
        Self {
            scopes: Vec::new(),
            scopes_by_node_id: HashMap::new(),
            scopes_by_file_id: HashMap::new(),
            global_using_directives: Vec::new(),
            definitions: HashMap::new(),
            definitions_by_identifier: HashMap::new(),
            references: HashMap::new(),
            node_typing: HashMap::new(),
            linearisations: HashMap::new(),
        }
    }

    pub(crate) fn get_scope_by_id(&self, scope_id: ScopeId) -> &Scope {
        self.scopes.get(scope_id.0).unwrap()
    }

    pub(crate) fn get_scope_mut(&mut self, scope_id: ScopeId) -> &mut Scope {
        self.scopes.get_mut(scope_id.0).unwrap()
    }

    pub(crate) fn scope_id_for_node_id(&self, node_id: NodeId) -> Option<ScopeId> {
        self.scopes_by_node_id.get(&node_id).copied()
    }

    pub(crate) fn scope_id_for_file_id(&self, file_id: &str) -> Option<ScopeId> {
        self.scopes_by_file_id.get(file_id).copied()
    }

    pub(crate) fn insert_scope(&mut self, scope: Scope) -> ScopeId {
        let scope_id = ScopeId(self.scopes.len());

        if let Scope::File(file_scope) = &scope {
            let file_id = &file_scope.file_id;
            if self
                .scopes_by_file_id
                .insert(file_id.clone(), scope_id)
                .is_some()
            {
                unreachable!("attempt to insert duplicate file scope for {file_id}");
            }
        }

        if let Scope::Parameters(_) = &scope {
            // parameters scope don't have an associated node ID
        } else {
            let node_id = scope.node_id();
            if self.scopes_by_node_id.insert(node_id, scope_id).is_some() {
                unreachable!("attempt to insert duplicate file scope for node {node_id:?}");
            }
        }

        self.scopes.push(scope);
        scope_id
    }

    pub(crate) fn insert_definition_no_scope(&mut self, definition: Definition) {
        let node_id = definition.node_id();
        if self.definitions.contains_key(&node_id) {
            unreachable!("attempt to insert duplicate definition on node {node_id:?}");
        }
        self.definitions_by_identifier
            .insert(definition.identifier().id(), node_id);
        self.definitions.insert(node_id, definition);
    }

    pub(crate) fn insert_definition_in_scope(&mut self, definition: Definition, scope_id: ScopeId) {
        let scope = self.get_scope_mut(scope_id);
        scope.insert_definition(&definition);
        self.insert_definition_no_scope(definition);
    }

    pub fn find_definition_by_id(&self, node_id: NodeId) -> Option<&Definition> {
        self.definitions.get(&node_id)
    }

    pub fn find_definition_by_identifier_node_id(&self, node_id: NodeId) -> Option<&Definition> {
        self.definitions_by_identifier
            .get(&node_id)
            .and_then(|definition_id| self.definitions.get(definition_id))
    }

    pub(crate) fn get_definition_mut(&mut self, node_id: NodeId) -> &mut Definition {
        self.definitions.get_mut(&node_id).unwrap()
    }

    pub(crate) fn insert_linearised_bases(
        &mut self,
        node_id: NodeId,
        linearised_bases: Vec<NodeId>,
    ) {
        if self
            .linearisations
            .insert(node_id, linearised_bases)
            .is_some()
        {
            unreachable!("Trying to linearised twice {node_id:?}");
        }
    }

    pub(crate) fn get_linearised_bases(&self, node_id: NodeId) -> Option<&Vec<NodeId>> {
        self.linearisations.get(&node_id)
    }

    #[cfg(feature = "__private_testing_utils")]
    pub fn linearisations(&self) -> &HashMap<NodeId, Vec<NodeId>> {
        &self.linearisations
    }

    pub fn definitions(&self) -> &HashMap<NodeId, Definition> {
        &self.definitions
    }

    pub(crate) fn insert_reference(&mut self, reference: Reference) {
        let node_id = reference.node_id();
        self.references.insert(node_id, reference);
    }

    pub(crate) fn fixup_reference(&mut self, node_id: NodeId, resolution: Resolution) {
        let reference = self.references.get_mut(&node_id).unwrap();
        reference.resolution = resolution;
    }

    pub fn find_reference_by_identifier_node_id(&self, node_id: NodeId) -> Option<&Reference> {
        self.references.get(&node_id)
    }

    pub fn references(&self) -> &HashMap<NodeId, Reference> {
        &self.references
    }

    pub(crate) fn insert_using_directive_in_scope(
        &mut self,
        directive: UsingDirective,
        scope_id: ScopeId,
    ) {
        let scope = self.get_scope_mut(scope_id);
        match scope {
            Scope::Contract(contract_scope) => contract_scope.using_directives.push(directive),
            Scope::File(file_scope) => file_scope.using_directives.push(directive),
            _ => unreachable!("cannot insert a using directive in scope {scope_id:?}"),
        }
    }

    pub(crate) fn insert_global_using_directive(&mut self, directive: UsingDirective) {
        self.global_using_directives.push(directive);
    }

    pub(crate) fn get_global_using_directives(&self) -> impl Iterator<Item = &UsingDirective> {
        self.global_using_directives.iter()
    }

    pub(crate) fn get_using_directives_in_scope(
        &self,
        scope_id: ScopeId,
    ) -> impl Iterator<Item = &UsingDirective> {
        self.get_scope_by_id(scope_id).get_using_directives()
    }

    pub(crate) fn get_using_directives_in_scope_including_inherited(
        &self,
        scope_id: ScopeId,
    ) -> impl Iterator<Item = &UsingDirective> {
        let scope = self.get_scope_by_id(scope_id);
        if let Scope::Contract(contract_scope) = scope {
            if let Some(linearisations) = self.linearisations.get(&contract_scope.node_id) {
                return EitherIter::Left(
                    linearisations
                        .iter()
                        .filter_map(|node_id| self.scope_id_for_node_id(*node_id))
                        .flat_map(|scope_id| self.get_scope_by_id(scope_id).get_using_directives()),
                );
            }
        }
        EitherIter::Right(scope.get_using_directives())
    }

    pub fn node_typing(&self, node_id: NodeId) -> Typing {
        self.node_typing
            .get(&node_id)
            .cloned()
            .expect("expected node to have typing information")
    }

    pub(crate) fn mark_user_meta_type_node(&mut self, node_id: NodeId) {
        self.node_typing
            .insert(node_id, Typing::UserMetaType(node_id));
    }

    pub(crate) fn set_node_type(&mut self, node_id: NodeId, type_id: Option<TypeId>) {
        let typing = if let Some(type_id) = type_id {
            Typing::Resolved(type_id)
        } else {
            Typing::Unresolved
        };
        self.set_node_typing(node_id, typing);
    }

    pub(crate) fn set_node_typing(&mut self, node_id: NodeId, typing: Typing) {
        let previous_typing = self.node_typing.insert(node_id, typing);
        if previous_typing.is_some() {
            unreachable!("typing information for node {node_id:?} already set");
        }
    }

    pub(crate) fn fixup_node_typing(&mut self, node_id: NodeId, typing: Typing) {
        assert!(
            self.node_typing.contains_key(&node_id),
            "typing information for node {node_id:?} not set"
        );
        self.node_typing.insert(node_id, typing);
    }

    // File scope resolution context

    fn get_file_scope(&self, file_id: &str) -> &FileScope {
        self.scopes_by_file_id
            .get(file_id)
            .and_then(|scope_id| self.scopes.get(scope_id.0))
            .and_then(|scope| match scope {
                Scope::File(file_scope) => Some(file_scope),
                _ => None,
            })
            .unwrap()
    }

    // Resolving a symbol in a file scope is special because of default imports.
    // We want to find *all* definitions with the given symbol reachable from
    // the file.
    fn resolve_in_file_scope(&self, file_id: &str, symbol: &str) -> Resolution {
        let mut found_definitions = Vec::new();
        let mut visited_files = HashSet::new();
        let mut files_to_search = VecDeque::new();
        files_to_search.push_back(file_id.to_owned());

        while let Some(file_id) = files_to_search.pop_front() {
            let file_scope = self.get_file_scope(&file_id);
            if !visited_files.insert(file_id) {
                continue;
            }

            found_definitions.extend(file_scope.lookup_symbol(symbol));
            files_to_search.extend(file_scope.imported_files.iter().cloned());
        }

        Resolution::from(found_definitions)
    }

    fn resolve_in_contract_scope_internal(
        &self,
        contract_scope: &ContractScope,
        symbol: &str,
        options: ResolveOptions,
    ) -> Resolution {
        // Search for the symbol in the linearised bases *in-order*.
        if let Some(linearisations) = self.linearisations.get(&contract_scope.node_id) {
            let linearisations = match options {
                ResolveOptions::Internal | ResolveOptions::External | ResolveOptions::Qualified => {
                    linearisations.as_slice()
                }
                ResolveOptions::This(node_id) => {
                    if let Some(index) = linearisations.iter().position(|id| *id == node_id) {
                        &linearisations[index..]
                    } else {
                        return Resolution::Unresolved;
                    }
                }
                ResolveOptions::Super(node_id) => {
                    if let Some(index) = linearisations.iter().position(|id| *id == node_id) {
                        &linearisations[index + 1..]
                    } else {
                        return Resolution::Unresolved;
                    }
                }
            };
            let mut results = Vec::new();
            for (index, node_id) in linearisations.iter().enumerate() {
                let Some(base_scope_id) = self.scope_id_for_node_id(*node_id) else {
                    continue;
                };
                let Scope::Contract(base_contract_scope) = self.get_scope_by_id(base_scope_id)
                else {
                    unreachable!("expected the scope of a base contract to be a ContractScope");
                };
                let Some(definitions) = base_contract_scope.definitions.get(symbol) else {
                    continue;
                };
                for definition_id in definitions {
                    let definition = &self.definitions[definition_id];
                    let visible = match options {
                        ResolveOptions::Internal => {
                            if index == 0 {
                                definition.is_private_or_internally_visible()
                            } else {
                                definition.is_internally_visible()
                            }
                        }
                        ResolveOptions::Qualified => {
                            index == 0
                                || definition.is_internally_visible()
                                || definition.is_externally_visible()
                        }
                        ResolveOptions::This(_) | ResolveOptions::External => {
                            definition.is_externally_visible()
                        }
                        ResolveOptions::Super(_) => definition.is_internally_visible(),
                    };
                    if visible {
                        results.push(*definition_id);
                    }
                }
            }
            Resolution::from(results)
        } else if let Some(definitions) = contract_scope.definitions.get(symbol) {
            // This case shouldn't happen for valid Solidity, as all
            // contracts should have a proper linearisation
            Resolution::from(definitions.clone())
        } else {
            Resolution::Unresolved
        }
    }

    fn resolve_in_scope_internal(&self, scope_id: ScopeId, symbol: &str) -> Resolution {
        let scope = self.get_scope_by_id(scope_id);
        match scope {
            Scope::Block(block_scope) => block_scope.definitions.get(symbol).copied().map_or_else(
                || self.resolve_in_scope_internal(block_scope.parent_scope_id, symbol),
                Resolution::Definition,
            ),
            Scope::Contract(contract_scope) => {
                self.resolve_in_contract_scope_internal(
                    contract_scope,
                    symbol,
                    ResolveOptions::Internal,
                )
                .or_else(|| {
                    // Otherwise, delegate to the containing file scope.
                    self.resolve_in_scope_internal(contract_scope.file_scope_id, symbol)
                })
            }
            Scope::Enum(enum_scope) => enum_scope.definitions.get(symbol).into(),
            Scope::File(file_scope) => self.resolve_in_file_scope(&file_scope.file_id, symbol),
            Scope::Function(function_scope) => function_scope
                .definitions
                .get(symbol)
                .copied()
                .map_or_else(
                    || self.resolve_in_scope_internal(function_scope.parameters_scope_id, symbol),
                    Resolution::Definition,
                )
                .or_else(|| self.resolve_in_scope_internal(function_scope.parent_scope_id, symbol)),
            Scope::Modifier(modifier_scope) => {
                if symbol == "_" {
                    Resolution::BuiltIn(BuiltIn::ModifierUnderscore)
                } else {
                    modifier_scope.definitions.get(symbol).copied().map_or_else(
                        || self.resolve_in_scope_internal(modifier_scope.parent_scope_id, symbol),
                        Resolution::Definition,
                    )
                }
            }
            Scope::Parameters(parameters_scope) => {
                parameters_scope.lookup_definition(symbol).into()
            }
            Scope::Struct(struct_scope) => struct_scope.definitions.get(symbol).into(),
            Scope::Using(using_scope) => using_scope
                .symbols
                .get(symbol)
                .cloned()
                .map_or(Resolution::Unresolved, Resolution::from),
            Scope::YulBlock(yul_block_scope) => yul_block_scope
                .definitions
                .get(symbol)
                .copied()
                .map_or_else(
                    || self.resolve_in_scope_internal(yul_block_scope.parent_scope_id, symbol),
                    Resolution::Definition,
                ),
            Scope::YulFunction(yul_function_scope) => {
                // TODO(validation): when delegating to the parent scope, we
                // cannot resolve to a Yul variable defined in a parent block
                yul_function_scope
                    .definitions
                    .get(symbol)
                    .copied()
                    .map_or_else(
                        || {
                            self.resolve_in_scope_internal(
                                yul_function_scope.parent_scope_id,
                                symbol,
                            )
                        },
                        Resolution::Definition,
                    )
            }
        }
    }

    // This will attempt to lexically resolve `symbol` starting from the given
    // scope. This means that scopes can delegate to their "parent" scopes if
    // the symbol is not found there, and also that imported symbols are
    // followed recursively. This function handles the latter (following
    // imported symbols recursively), while `resolve_in_scope_internal`
    // delegates to parent or otherwise linked scopes.
    pub(crate) fn resolve_in_scope(&self, scope_id: ScopeId, symbol: &str) -> Resolution {
        // TODO: since this function uses the results from other resolution
        // functions, we making more allocations than necessary; it may be worth
        // it to try and avoid them by returning iterators from the delegated
        // resolution functions
        let mut found_ids = Vec::new();
        let mut working_set = Vec::new();
        let mut seen_ids = HashSet::new();

        let initial_resolution = self.resolve_in_scope_internal(scope_id, symbol);
        match initial_resolution {
            Resolution::Unresolved | Resolution::BuiltIn(_) => return initial_resolution,
            _ => {}
        }

        working_set.extend(initial_resolution.get_definition_ids().iter().rev());
        while let Some(definition_id) = working_set.pop() {
            if !seen_ids.insert(definition_id) {
                // we already processed this definition
                continue;
            }
            let Some(definition) = self.find_definition_by_id(definition_id) else {
                unreachable!("Definition {definition_id:?} does not exist");
            };
            if let Definition::ImportedSymbol(imported_symbol) = definition {
                // follow the imported symbol and expand the working set
                let Some(scope_id) = imported_symbol
                    .resolved_file_id
                    .as_ref()
                    .and_then(|file_id| self.scope_id_for_file_id(file_id))
                else {
                    continue;
                };
                working_set.extend(
                    self.resolve_in_scope_internal(scope_id, &imported_symbol.symbol)
                        .get_definition_ids()
                        .iter()
                        .rev(),
                );
            } else {
                found_ids.push(definition_id);
            }
        }

        Resolution::from(found_ids)
    }

    // Resolution in this function is strictly limited to the given scope, and
    // will only work in scope types that can work as a namespace only (eg.
    // block scopes and other lexical scopes don't)
    pub(crate) fn resolve_in_scope_as_namespace(
        &self,
        scope_id: ScopeId,
        symbol: &str,
    ) -> Resolution {
        let scope = self.get_scope_by_id(scope_id);
        match scope {
            Scope::Contract(contract_scope) => self.resolve_in_contract_scope_internal(
                contract_scope,
                symbol,
                ResolveOptions::Qualified,
            ),
            Scope::Enum(enum_scope) => enum_scope.definitions.get(symbol).into(),
            Scope::Struct(struct_scope) => struct_scope.definitions.get(symbol).into(),
            Scope::Using(using_scope) => using_scope
                .symbols
                .get(symbol)
                .cloned()
                .map_or(Resolution::Unresolved, Resolution::from),
            Scope::Parameters(parameters_scope) => {
                parameters_scope.lookup_definition(symbol).into()
            }

            Scope::Block(_)
            | Scope::File(_)
            | Scope::Function(_)
            | Scope::Modifier(_)
            | Scope::YulBlock(_)
            | Scope::YulFunction(_) => Resolution::Unresolved,
        }
    }

    pub(crate) fn resolve_in_contract_scope(
        &self,
        scope_id: ScopeId,
        symbol: &str,
        options: ResolveOptions,
    ) -> Resolution {
        let scope = self.get_scope_by_id(scope_id);
        if let Scope::Contract(contract_scope) = scope {
            self.resolve_in_contract_scope_internal(contract_scope, symbol, options)
        } else {
            Resolution::Unresolved
        }
    }

    pub(crate) fn get_parameters_scope_for_definition(
        &self,
        definition_id: NodeId,
    ) -> Option<ScopeId> {
        match self.find_definition_by_id(definition_id)? {
            Definition::Contract(contract_definition) => {
                contract_definition.constructor_parameters_scope_id
            }
            Definition::Error(error_definition) => Some(error_definition.parameters_scope_id),
            Definition::Event(event_definition) => Some(event_definition.parameters_scope_id),
            Definition::Function(function_definition) => {
                Some(function_definition.parameters_scope_id)
            }
            Definition::Struct(_) => self.scope_id_for_node_id(definition_id),
            _ => None,
        }
    }
}