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

Missing span for TypeProperty #1250

Merged
merged 1 commit into from
Apr 14, 2022
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
4 changes: 3 additions & 1 deletion sway-core/src/asm_generation/expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,9 @@ pub(crate) fn convert_expression_to_asm(
namespace,
register_sequencer,
),
TypedExpressionVariant::TypeProperty { property, type_id } => match property {
TypedExpressionVariant::TypeProperty {
property, type_id, ..
} => match property {
BuiltinProperty::SizeOfType => convert_size_of_to_asm(
None,
type_id,
Expand Down
35 changes: 22 additions & 13 deletions sway-core/src/optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,8 +699,12 @@ impl FnCompiler {
let span_md_idx = MetadataIndex::from_span(context, &access.span());
self.compile_storage_access(context, &access.fields, &access.ix, span_md_idx)
}
TypedExpressionVariant::TypeProperty { property, type_id } => {
let ir_type = convert_resolved_typeid_no_span(context, &type_id)?;
TypedExpressionVariant::TypeProperty {
property,
type_id,
span,
} => {
let ir_type = convert_resolved_typeid(context, &type_id, &span)?;
match property {
BuiltinProperty::SizeOfType => Ok(Constant::get_uint(
context,
Expand Down Expand Up @@ -2343,6 +2347,7 @@ fn convert_resolved_typeid(
context,
&resolve_type(*ast_type, span)
.map_err(|ty_err| CompileError::InternalOwned(format!("{ty_err:?}"), span.clone()))?,
span,
)
}

Expand All @@ -2358,7 +2363,11 @@ fn convert_resolved_typeid_no_span(
convert_resolved_typeid(context, ast_type, &span)
}

fn convert_resolved_type(context: &mut Context, ast_type: &TypeInfo) -> Result<Type, CompileError> {
fn convert_resolved_type(
context: &mut Context,
ast_type: &TypeInfo,
span: &Span,
) -> Result<Type, CompileError> {
Ok(match ast_type {
// All integers are `u64`, see comment in convert_literal_to_value() above.
TypeInfo::UnsignedInteger(_) => Type::Uint(64),
Expand All @@ -2380,7 +2389,7 @@ fn convert_resolved_type(context: &mut Context, ast_type: &TypeInfo) -> Result<T
create_enum_aggregate(context, variant_types.clone()).map(&Type::Struct)?
}
TypeInfo::Array(elem_type_id, count) => {
let elem_type = convert_resolved_typeid_no_span(context, elem_type_id)?;
let elem_type = convert_resolved_typeid(context, elem_type_id, span)?;
Type::Array(Aggregate::new_array(context, elem_type, *count as u64))
}
TypeInfo::Tuple(fields) => {
Expand All @@ -2400,55 +2409,55 @@ fn convert_resolved_type(context: &mut Context, ast_type: &TypeInfo) -> Result<T
TypeInfo::Custom { .. } => {
return Err(CompileError::Internal(
"Custom type cannot be resolved in IR.",
Span::empty(),
span.clone(),
))
}
TypeInfo::SelfType { .. } => {
return Err(CompileError::Internal(
"Self type cannot be resolved in IR.",
Span::empty(),
span.clone(),
))
}
TypeInfo::Contract => {
return Err(CompileError::Internal(
"Contract type cannot be resolved in IR.",
Span::empty(),
span.clone(),
))
}
TypeInfo::ContractCaller { .. } => {
return Err(CompileError::Internal(
"ContractCaller type cannot be reoslved in IR.",
Span::empty(),
span.clone(),
))
}
TypeInfo::Unknown => {
return Err(CompileError::Internal(
"Unknown type cannot be resolved in IR.",
Span::empty(),
span.clone(),
))
}
TypeInfo::UnknownGeneric { .. } => {
return Err(CompileError::Internal(
"Generic type cannot be resolved in IR.",
Span::empty(),
span.clone(),
))
}
TypeInfo::Ref(_) => {
return Err(CompileError::Internal(
"Ref type cannot be resolved in IR.",
Span::empty(),
span.clone(),
))
}
TypeInfo::ErrorRecovery => {
return Err(CompileError::Internal(
"Error recovery type cannot be resolved in IR.",
Span::empty(),
span.clone(),
))
}
TypeInfo::Storage { .. } => {
return Err(CompileError::Internal(
"Storage type cannot be resolved in IR.",
Span::empty(),
span.clone(),
))
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2411,6 +2411,7 @@ impl TypedExpression {
expression: TypedExpressionVariant::TypeProperty {
property: builtin,
type_id,
span: span.clone(),
},
return_type,
is_constant: IsConstant::No,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ pub(crate) enum TypedExpressionVariant {
TypeProperty {
property: BuiltinProperty,
type_id: TypeId,
span: Span,
},
SizeOfValue {
expr: Box<TypedExpression>,
Expand Down Expand Up @@ -331,10 +332,12 @@ impl PartialEq for TypedExpressionVariant {
Self::TypeProperty {
property: l_prop,
type_id: l_type_id,
..
},
Self::TypeProperty {
property: r_prop,
type_id: r_type_id,
..
},
) => l_prop == r_prop && look_up_type_id(*l_type_id) == look_up_type_id(*r_type_id),
(Self::SizeOfValue { expr: l_expr }, Self::SizeOfValue { expr: r_expr }) => {
Expand Down Expand Up @@ -499,7 +502,9 @@ impl TypedExpressionVariant {
TypedExpressionVariant::StorageAccess(access) => {
format!("storage field {} access", access.storage_field_name())
}
TypedExpressionVariant::TypeProperty { property, type_id } => {
TypedExpressionVariant::TypeProperty {
property, type_id, ..
} => {
let type_str = look_up_type_id(*type_id).friendly_type_str();
match property {
BuiltinProperty::SizeOfType => format!("size_of({type_str:?})"),
Expand Down