Skip to content

Commit

Permalink
Struct field type checking fix; Bad error message fix (FuelLabs#110)
Browse files Browse the repository at this point in the history
* improve error reporting when a method is called on an error

* Fix struct subfield access type checking bug

* Remove bad error message when function argument has an error

* clean up stdlib test suite

Co-authored-by: Alexander Hansen <[email protected]>
  • Loading branch information
sezna and Alexander Hansen authored Jul 5, 2021
1 parent 8d18513 commit b6facc6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 24 deletions.
2 changes: 1 addition & 1 deletion core_lang/src/asm_generation/expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ fn convert_fn_app_to_asm<'sc>(
let return_register = register_sequencer.next();
let mut ops = type_check!(
convert_expression_to_asm(arg, &mut namespace, &return_register, register_sequencer),
continue,
vec![],
warnings,
errors
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ impl<'sc> TypedExpression<'sc> {
TypedExpression {
expression: TypedExpressionVariant::StructFieldAccess {
unary_op,
resolved_type_of_parent: MaybeResolvedType::Resolved(field.r#type.clone()),
resolved_type_of_parent: parent.return_type.clone(),
prefix: Box::new(parent),
field_to_access: field.clone(),
},
Expand Down Expand Up @@ -608,11 +608,15 @@ impl<'sc> TypedExpression<'sc> {
{
Some(o) => o,
None => {
errors.push(CompileError::MethodNotFound {
method_name: method_name.primary_name,
type_name: args_buf[0].return_type.friendly_type_str(),
span: method_name.span.clone(),
});
if args_buf[0].return_type
!= MaybeResolvedType::Resolved(ResolvedType::ErrorRecovery)
{
errors.push(CompileError::MethodNotFound {
method_name: method_name.primary_name,
type_name: args_buf[0].return_type.friendly_type_str(),
span: method_name.span.clone(),
});
}
return err(warnings, errors);
}
};
Expand Down Expand Up @@ -693,11 +697,15 @@ impl<'sc> TypedExpression<'sc> {
{
Some(o) => o,
None => {
errors.push(CompileError::MethodNotFound {
method_name: call_path.suffix.primary_name.clone(),
type_name: type_name.friendly_type_str(),
span: call_path.suffix.span.clone(),
});
if type_name
!= MaybeResolvedType::Resolved(ResolvedType::ErrorRecovery)
{
errors.push(CompileError::MethodNotFound {
method_name: call_path.suffix.primary_name.clone(),
type_name: type_name.friendly_type_str(),
span: call_path.suffix.span.clone(),
});
}
return err(warnings, errors);
}
}
Expand All @@ -714,11 +722,15 @@ impl<'sc> TypedExpression<'sc> {
match module.find_method_for_type(r#type, call_path.suffix.clone()) {
Some(o) => o,
None => {
errors.push(CompileError::MethodNotFound {
method_name: call_path.suffix.primary_name.clone(),
type_name: r#type.friendly_type_str(),
span: call_path.suffix.span.clone(),
});
if *r#type
!= MaybeResolvedType::Resolved(ResolvedType::ErrorRecovery)
{
errors.push(CompileError::MethodNotFound {
method_name: call_path.suffix.primary_name.clone(),
type_name: r#type.friendly_type_str(),
span: call_path.suffix.span.clone(),
});
}
return err(warnings, errors);
}
}
Expand Down Expand Up @@ -758,8 +770,6 @@ impl<'sc> TypedExpression<'sc> {
is_constant: IsConstant::No,
span,
}

// todo!("fnd the namespace of the call_path and resolve the type_name in it. then grab the method name. emthod name is the call_path suffix")
}
}
}
Expand Down
13 changes: 8 additions & 5 deletions core_lang/src/semantic_analysis/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,11 +583,14 @@ impl<'sc> Namespace<'sc> {
a => {
return err(
vec![],
vec![CompileError::NotAStruct {
name: debug_string.into(),
span: debug_span.clone(),
actually: a.friendly_type_str(),
}],
match a {
MaybeResolvedType::Resolved(ResolvedType::ErrorRecovery) => vec![],
_ => vec![CompileError::NotAStruct {
name: debug_string.into(),
span: debug_span.clone(),
actually: a.friendly_type_str(),
}],
},
)
}
}
Expand Down

0 comments on commit b6facc6

Please sign in to comment.