diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-11-17 16:45:50 +0000 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2021-11-17 16:45:50 +0000 |
commit | 649e2ec5682ed8007987f2acb4899892a81cc18f (patch) | |
tree | 3a0b255d3dc86e0de693718441c4d12cec76c9aa /gcc | |
parent | e584c6f8a7805b1ddc9fe97065cd8f1bac734fc2 (diff) | |
download | gcc-649e2ec5682ed8007987f2acb4899892a81cc18f.zip gcc-649e2ec5682ed8007987f2acb4899892a81cc18f.tar.gz gcc-649e2ec5682ed8007987f2acb4899892a81cc18f.tar.bz2 |
Unify the adjusted self argument to the self parameter on MethodCalls
When we must infer the substitutions on method calls we must make sure to
unify the self arguments from the receiver, taking into account the
autoderef mechanism. This enforces the type checks and fixes up any
inference variables along the way.
Addresses #808
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-expr.h | 7 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-tyty-call.h | 9 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-tyty.cc | 2 |
3 files changed, 14 insertions, 4 deletions
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h index 99696ae..d5d12b4 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.h +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h @@ -295,6 +295,10 @@ public: return; } + // Get the adjusted self + Adjuster adj (receiver_tyty); + TyTy::BaseType *adjusted_self = adj.adjust_type (adjustments); + // store the adjustments for code-generation to know what to do context->insert_autoderef_mappings (expr.get_mappings ().get_hirid (), std::move (adjustments)); @@ -401,7 +405,8 @@ public: } TyTy::BaseType *function_ret_tyty - = TyTy::TypeCheckMethodCallExpr::go (lookup, expr, context); + = TyTy::TypeCheckMethodCallExpr::go (lookup, expr, adjusted_self, + context); if (function_ret_tyty == nullptr || function_ret_tyty->get_kind () == TyTy::TypeKind::ERROR) { diff --git a/gcc/rust/typecheck/rust-tyty-call.h b/gcc/rust/typecheck/rust-tyty-call.h index c11fd4d..3080427 100644 --- a/gcc/rust/typecheck/rust-tyty-call.h +++ b/gcc/rust/typecheck/rust-tyty-call.h @@ -88,9 +88,10 @@ class TypeCheckMethodCallExpr : private TyVisitor public: // Resolve the Method parameters and return back the return type static BaseType *go (BaseType *ref, HIR::MethodCallExpr &call, + TyTy::BaseType *adjusted_self, Resolver::TypeCheckContext *context) { - TypeCheckMethodCallExpr checker (call, context); + TypeCheckMethodCallExpr checker (call, adjusted_self, context); ref->accept_vis (checker); return checker.resolved; } @@ -125,13 +126,15 @@ public: private: TypeCheckMethodCallExpr (HIR::MethodCallExpr &c, + TyTy::BaseType *adjusted_self, Resolver::TypeCheckContext *context) - : resolved (nullptr), call (c), context (context), - mappings (Analysis::Mappings::get ()) + : resolved (nullptr), call (c), adjusted_self (adjusted_self), + context (context), mappings (Analysis::Mappings::get ()) {} BaseType *resolved; HIR::MethodCallExpr &call; + TyTy::BaseType *adjusted_self; Resolver::TypeCheckContext *context; Analysis::Mappings *mappings; }; diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index 378416f..add4dbe 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -2786,6 +2786,8 @@ TypeCheckCallExpr::visit (FnPtr &type) void TypeCheckMethodCallExpr::visit (FnType &type) { + adjusted_self->unify (type.get_self_type ()); + // +1 for the receiver self size_t num_args_to_call = call.num_params () + 1; if (num_args_to_call != type.num_params ()) |