Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the CopyTypes trait to DeclarationId #2682

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions sway-core/src/declaration_engine/declaration_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use std::fmt;

use sway_types::{Span, Spanned};

use crate::type_system::{CopyTypes, TypeMapping};

use super::declaration_engine::de_look_up_decl_id;

/// An ID used to refer to an item in the [DeclarationEngine](super::declaration_engine::DeclarationEngine)
Expand Down Expand Up @@ -49,6 +51,12 @@ impl Spanned for DeclarationId {
}
}

impl CopyTypes for DeclarationId {
fn copy_types(&mut self, type_mapping: &TypeMapping) {
de_look_up_decl_id(self.clone()).copy_types(type_mapping)
}
}

impl DeclarationId {
pub(super) fn new(index: usize, span: Span) -> DeclarationId {
DeclarationId(index, span)
Expand Down
15 changes: 15 additions & 0 deletions sway-core/src/declaration_engine/declaration_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{
TypedImplTrait, TypedStorageDeclaration, TypedStructDeclaration, TypedTraitDeclaration,
TypedTraitFn,
},
type_system::{CopyTypes, TypeMapping},
CompileError, TypedFunctionDeclaration,
};

Expand Down Expand Up @@ -54,6 +55,20 @@ impl fmt::Display for DeclarationWrapper {
}
}

impl CopyTypes for DeclarationWrapper {
fn copy_types(&mut self, type_mapping: &TypeMapping) {
match self {
DeclarationWrapper::Unknown => {}
DeclarationWrapper::Function(decl) => decl.copy_types(type_mapping),
DeclarationWrapper::Trait(decl) => decl.copy_types(type_mapping),
DeclarationWrapper::TraitFn(decl) => decl.copy_types(type_mapping),
DeclarationWrapper::TraitImpl(decl) => decl.copy_types(type_mapping),
DeclarationWrapper::Struct(decl) => decl.copy_types(type_mapping),
DeclarationWrapper::Storage(_) => {}
}
}
}

impl DeclarationWrapper {
/// friendly name string used for error reporting.
fn friendly_name(&self) -> &'static str {
Expand Down