Skip to content

Commit

Permalink
revert to passing along declaration Ident but also pass on the callin…
Browse files Browse the repository at this point in the history
…g site span
  • Loading branch information
JoshuaBatty committed Jul 26, 2022
1 parent 9323fa9 commit 42e79ef
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions sway-core/src/control_flow_analysis/dead_code_analysis.rs
Expand Up @@ -821,6 +821,7 @@ fn connect_expression(
StructExpression {
struct_name,
fields,
..
} => {
let decl = match graph.namespace.find_struct_decl(struct_name.as_str()) {
Some(ix) => *ix,
Expand Down
Expand Up @@ -954,16 +954,14 @@ impl TypedExpression {

// extract the struct name and fields from the type info
let type_info = look_up_type_id(type_id);
let struct_fields = check!(
let (struct_name, 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 @@ -1021,8 +1019,9 @@ impl TypedExpression {
}
let exp = TypedExpression {
expression: TypedExpressionVariant::StructExpression {
struct_name,
struct_name: struct_name.clone(),
fields: typed_fields_buf,
span: call_path_binding.inner.suffix.1.clone(),
},
return_type: type_id,
is_constant: IsConstant::No,
Expand Down
Expand Up @@ -49,6 +49,7 @@ pub enum TypedExpressionVariant {
StructExpression {
struct_name: Ident,
fields: Vec<TypedStructExpressionField>,
span: Span,
},
CodeBlock(TypedCodeBlock),
// a flag that this value will later be provided as a parameter, but is currently unknown
Expand Down Expand Up @@ -177,12 +178,18 @@ impl PartialEq for TypedExpressionVariant {
Self::StructExpression {
struct_name: l_struct_name,
fields: l_fields,
span: l_span,
},
Self::StructExpression {
struct_name: r_struct_name,
fields: r_fields,
span: r_span,
},
) => l_struct_name == r_struct_name && l_fields.clone() == r_fields.clone(),
) => {
l_struct_name == r_struct_name
&& l_fields.clone() == r_fields.clone()
&& l_span == r_span
}
(Self::CodeBlock(l0), Self::CodeBlock(r0)) => l0 == r0,
(
Self::IfExp {
Expand Down
7 changes: 5 additions & 2 deletions sway-core/src/type_engine/type_info.rs
Expand Up @@ -1276,11 +1276,14 @@ 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<&Vec<TypedStructField>> {
pub(crate) fn expect_struct(
&self,
debug_span: &Span,
) -> CompileResult<(&Ident, &Vec<TypedStructField>)> {
let warnings = vec![];
let errors = vec![];
match self {
TypeInfo::Struct { fields, .. } => ok(fields, warnings, errors),
TypeInfo::Struct { name, fields, .. } => ok((name, fields), warnings, errors),
TypeInfo::ErrorRecovery => err(warnings, errors),
a => err(
vec![],
Expand Down
7 changes: 2 additions & 5 deletions sway-lsp/src/core/traverse_typed_tree.rs
Expand Up @@ -230,11 +230,8 @@ fn handle_expression(expression: &TypedExpression, tokens: &TokenMap) {
handle_expression(prefix, tokens);
handle_expression(index, tokens);
}
TypedExpressionVariant::StructExpression {
ref struct_name,
ref fields,
} => {
if let Some(mut token) = tokens.get_mut(&to_ident_key(struct_name)) {
TypedExpressionVariant::StructExpression { fields, span, .. } => {
if let Some(mut token) = tokens.get_mut(&to_ident_key(&Ident::new(span.clone()))) {
token.typed = Some(TypedAstToken::TypedExpression(expression.clone()));
}

Expand Down

0 comments on commit 42e79ef

Please sign in to comment.