public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Thomas Schwinge <tschwinge@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] Remove old hack to handle type inferencing in untyped decalred bindings Date: Wed, 8 Jun 2022 12:49:54 +0000 (GMT) [thread overview] Message-ID: <20220608124954.44F05388B584@sourceware.org> (raw) https://gcc.gnu.org/g:d01ae2ab56be6b515a863184baad496c50363fe6 commit d01ae2ab56be6b515a863184baad496c50363fe6 Author: Philip Herron <philip.herron@embecosm.com> Date: Tue May 24 15:43:53 2022 +0100 Remove old hack to handle type inferencing in untyped decalred bindings In the case where you define let a; with no type to then use this binding and let type inferencing infer the type we used this code to implicitly generate a new type binding to the resolved node id of the the lvalue. This was very dangerous and was always meant to be a stop gap untill we supported more of type inferencing. The issue here was that we were badly overriting a function types within the type-context which hits an ICE in the method resolution code which is expecting function TyTy's within in order to match methods correctly. Fixes #1274 #1273 Diff: --- gcc/rust/typecheck/rust-hir-type-check-expr.h | 41 +-------------------------- 1 file changed, 1 insertion(+), 40 deletions(-) diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h index b20a048865d..8145c5a741b 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.h +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h @@ -384,46 +384,7 @@ public: auto lhs = TypeCheckExpr::Resolve (expr.get_lhs (), false); auto rhs = TypeCheckExpr::Resolve (expr.get_rhs (), false); - auto result = lhs->coerce (rhs); - if (result->get_kind () == TyTy::TypeKind::ERROR) - return; - - // in the case of declare first for an ADT Type: - // - // let a; - // a = Foo{..} - // let b = a.field; - // - // The lhs will have a TyTy of INFER and so when the declaration is - // referenced it will still have an unknown type so we will fail to resolve - // FieldAccessExpr - - NodeId ast_node_id = expr.get_lhs ()->get_mappings ().get_nodeid (); - NodeId ref_node_id; - if (!resolver->lookup_resolved_name (ast_node_id, &ref_node_id)) - return; - - Definition def; - if (!resolver->lookup_definition (ref_node_id, &def)) - { - rust_error_at (expr.get_locus (), - "assignment infer - unknown reference"); - return; - } - - HirId ref; - if (!mappings->lookup_node_to_hir (expr.get_mappings ().get_crate_num (), - def.parent, &ref)) - { - rust_error_at (expr.get_locus (), - "assignment infer - reverse lookup failure"); - return; - } - - context->insert_type ( - Analysis::NodeMapping (expr.get_lhs ()->get_mappings ().get_crate_num (), - ref_node_id, ref, UNKNOWN_LOCAL_DEFID), - result->clone ()); + lhs->coerce (rhs); } void visit (HIR::CompoundAssignmentExpr &expr) override
reply other threads:[~2022-06-08 12:49 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220608124954.44F05388B584@sourceware.org \ --to=tschwinge@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).