aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-09-17 14:15:31 +0100
committerPhilip Herron <philip.herron@embecosm.com>2021-09-17 15:46:42 +0100
commite29a8a4172ae5c4f85d0e21d7edfaf934744c9fb (patch)
tree98f1af69c6ba1c718ab680751a2129eeaadbbab0 /gcc
parentecb777cc8df55a024add203e858486eadcc3aa62 (diff)
downloadgcc-e29a8a4172ae5c4f85d0e21d7edfaf934744c9fb.zip
gcc-e29a8a4172ae5c4f85d0e21d7edfaf934744c9fb.tar.gz
gcc-e29a8a4172ae5c4f85d0e21d7edfaf934744c9fb.tar.bz2
Cleanup error handling for CallExpr
Call Expressions need to type check the argument passing but the type system will return TyTy::Error nodes, it used to return nullptr about a year ago. Returning error nodes are safer and more flexible for detailed error handling and diagnostics. Addresses: #539
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/typecheck/rust-tyty.cc16
-rw-r--r--gcc/testsuite/rust/compile/tuple_struct3.rs6
2 files changed, 13 insertions, 9 deletions
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index 69fb8c4..dd33975 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -2352,14 +2352,14 @@ TypeCheckCallExpr::visit (ADTType &type)
BaseType *field_tyty = field->get_field_type ();
BaseType *arg = Resolver::TypeCheckExpr::Resolve (p, false);
- if (arg == nullptr)
+ if (arg->get_kind () == TyTy::TypeKind::ERROR)
{
rust_error_at (p->get_locus (), "failed to resolve argument type");
return false;
}
auto res = field_tyty->unify (arg);
- if (res == nullptr)
+ if (res->get_kind () == TyTy::TypeKind::ERROR)
{
return false;
}
@@ -2407,7 +2407,7 @@ TypeCheckCallExpr::visit (FnType &type)
size_t i = 0;
call.iterate_params ([&] (HIR::Expr *param) mutable -> bool {
auto argument_expr_tyty = Resolver::TypeCheckExpr::Resolve (param, false);
- if (argument_expr_tyty == nullptr)
+ if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR)
{
rust_error_at (param->get_locus (),
"failed to resolve type for argument expr in CallExpr");
@@ -2421,7 +2421,7 @@ TypeCheckCallExpr::visit (FnType &type)
{
auto fnparam = type.param_at (i);
resolved_argument_type = fnparam.second->unify (argument_expr_tyty);
- if (resolved_argument_type == nullptr)
+ if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR)
{
rust_error_at (param->get_locus (),
"Type Resolution failure on parameter");
@@ -2472,7 +2472,7 @@ TypeCheckCallExpr::visit (FnPtr &type)
call.iterate_params ([&] (HIR::Expr *param) mutable -> bool {
auto fnparam = type.param_at (i);
auto argument_expr_tyty = Resolver::TypeCheckExpr::Resolve (param, false);
- if (argument_expr_tyty == nullptr)
+ if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR)
{
rust_error_at (param->get_locus (),
"failed to resolve type for argument expr in CallExpr");
@@ -2480,7 +2480,7 @@ TypeCheckCallExpr::visit (FnPtr &type)
}
auto resolved_argument_type = fnparam->unify (argument_expr_tyty);
- if (resolved_argument_type == nullptr)
+ if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR)
{
rust_error_at (param->get_locus (),
"Type Resolution failure on parameter");
@@ -2523,7 +2523,7 @@ TypeCheckMethodCallExpr::visit (FnType &type)
call.iterate_params ([&] (HIR::Expr *param) mutable -> bool {
auto fnparam = type.param_at (i);
auto argument_expr_tyty = Resolver::TypeCheckExpr::Resolve (param, false);
- if (argument_expr_tyty == nullptr)
+ if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR)
{
rust_error_at (param->get_locus (),
"failed to resolve type for argument expr in CallExpr");
@@ -2531,7 +2531,7 @@ TypeCheckMethodCallExpr::visit (FnType &type)
}
auto resolved_argument_type = fnparam.second->unify (argument_expr_tyty);
- if (resolved_argument_type == nullptr)
+ if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR)
{
rust_error_at (param->get_locus (),
"Type Resolution failure on parameter");
diff --git a/gcc/testsuite/rust/compile/tuple_struct3.rs b/gcc/testsuite/rust/compile/tuple_struct3.rs
index c52a610..1af72a2 100644
--- a/gcc/testsuite/rust/compile/tuple_struct3.rs
+++ b/gcc/testsuite/rust/compile/tuple_struct3.rs
@@ -1,5 +1,9 @@
struct Foo(i32, i32, bool);
fn main() {
- let c = Foo(1, 2f32, true); // { dg-error "expected .i32. got .f32." }
+ let c = Foo(1, 2f32, true);
+ // { dg-error "expected .i32. got .f32." "" { target *-*-* } .-1 }
+ // { dg-error "unexpected number of arguments 1 expected 3" "" { target *-*-* } .-2 }
+ // { dg-error "failed to lookup type to CallExpr" "" { target *-*-* } .-3 }
+ // { dg-error "failed to type resolve expression" "" { target *-*-* } .-4 }
}