aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-02-08 15:51:54 +0000
committerPhilip Herron <herron.philip@googlemail.com>2021-02-09 09:47:35 +0000
commitb96299b0b96b6714d5a7b03fa6d4f1ea7d09fc44 (patch)
treeec392cdf34bc5bdd5d9193745c4b0b48a4db8cbb /gcc/rust/backend
parent60cccd8e58f2a024676599cc00971a6e406e6d42 (diff)
downloadgcc-b96299b0b96b6714d5a7b03fa6d4f1ea7d09fc44.zip
gcc-b96299b0b96b6714d5a7b03fa6d4f1ea7d09fc44.tar.gz
gcc-b96299b0b96b6714d5a7b03fa6d4f1ea7d09fc44.tar.bz2
Fix bad type resolution for CallExpr when fn is not simply PathInExpression
When we have a function that is for example a FieldAccessExpression the compiler must resolve and compile that field into a reference which can be called. This is not simple direct call to a function in that senario. Fixes #217
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r--gcc/rust/backend/rust-compile.cc46
1 files changed, 20 insertions, 26 deletions
diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc
index 0b83c72..600b2f9 100644
--- a/gcc/rust/backend/rust-compile.cc
+++ b/gcc/rust/backend/rust-compile.cc
@@ -53,33 +53,9 @@ CompileCrate::go ()
void
CompileExpr::visit (HIR::CallExpr &expr)
{
- // this can be a function call or it can be a constructor for a tuple struct
- Bexpression *fn = ResolvePathRef::Compile (expr.get_fnexpr (), ctx);
- if (fn != nullptr)
+ Btype *type = ResolvePathType::Compile (expr.get_fnexpr (), ctx);
+ if (type != nullptr)
{
- std::vector<Bexpression *> args;
- expr.iterate_params ([&] (HIR::Expr *p) mutable -> bool {
- Bexpression *compiled_expr = CompileExpr::Compile (p, ctx);
- rust_assert (compiled_expr != nullptr);
- args.push_back (compiled_expr);
- return true;
- });
-
- auto fncontext = ctx->peek_fn ();
- translated
- = ctx->get_backend ()->call_expression (fncontext.fndecl, fn, args,
- nullptr, expr.get_locus ());
- }
- else
- {
- Btype *type = ResolvePathType::Compile (expr.get_fnexpr (), ctx);
- if (type == nullptr)
- {
- rust_fatal_error (expr.get_locus (),
- "failed to lookup type associated with call");
- return;
- }
-
// this assumes all fields are in order from type resolution and if a base
// struct was specified those fields are filed via accesors
std::vector<Bexpression *> vals;
@@ -93,6 +69,24 @@ CompileExpr::visit (HIR::CallExpr &expr)
= ctx->get_backend ()->constructor_expression (type, vals,
expr.get_locus ());
}
+ else
+ {
+ // must be a call to a function
+ Bexpression *fn = CompileExpr::Compile (expr.get_fnexpr (), ctx);
+
+ std::vector<Bexpression *> args;
+ expr.iterate_params ([&] (HIR::Expr *p) mutable -> bool {
+ Bexpression *compiled_expr = CompileExpr::Compile (p, ctx);
+ rust_assert (compiled_expr != nullptr);
+ args.push_back (compiled_expr);
+ return true;
+ });
+
+ auto fncontext = ctx->peek_fn ();
+ translated
+ = ctx->get_backend ()->call_expression (fncontext.fndecl, fn, args,
+ nullptr, expr.get_locus ());
+ }
}
void