Skip to content

Commit

Permalink
return the local struct span instead of decleration Ident
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaBatty committed Jul 26, 2022
1 parent aa5dc0d commit 9323fa9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
Expand Up @@ -954,14 +954,16 @@ impl TypedExpression {

// extract the struct name and fields from the type info
let type_info = look_up_type_id(type_id);
let (struct_name, struct_fields) = check!(
let struct_fields = check!(
type_info.expect_struct(&span),
return err(warnings, errors),
warnings,
errors
);
let mut struct_fields = struct_fields.clone();

let struct_name = Ident::new(call_path_binding.inner.suffix.1.clone());

// match up the names with their type annotations from the declaration
let mut typed_fields_buf = vec![];
for def_field in struct_fields.iter_mut() {
Expand Down Expand Up @@ -1019,7 +1021,7 @@ impl TypedExpression {
}
let exp = TypedExpression {
expression: TypedExpressionVariant::StructExpression {
struct_name: struct_name.clone(),
struct_name,
fields: typed_fields_buf,
},
return_type: type_id,
Expand Down
7 changes: 2 additions & 5 deletions sway-core/src/type_engine/type_info.rs
Expand Up @@ -1276,14 +1276,11 @@ impl TypeInfo {
/// and return its contents.
///
/// Returns an error if `self` is not a `TypeInfo::Struct`.
pub(crate) fn expect_struct(
&self,
debug_span: &Span,
) -> CompileResult<(&Ident, &Vec<TypedStructField>)> {
pub(crate) fn expect_struct(&self, debug_span: &Span) -> CompileResult<&Vec<TypedStructField>> {
let warnings = vec![];
let errors = vec![];
match self {
TypeInfo::Struct { name, fields, .. } => ok((name, fields), warnings, errors),
TypeInfo::Struct { fields, .. } => ok(fields, warnings, errors),
TypeInfo::ErrorRecovery => err(warnings, errors),
a => err(
vec![],
Expand Down

0 comments on commit 9323fa9

Please sign in to comment.