diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-08-27 14:17:34 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2021-08-27 14:17:34 +0100 |
commit | 1fc2a7fe7e2351e560e75a0a17960816728aa419 (patch) | |
tree | f8347335eef7a33e15de18afc2d223566784a9c2 | |
parent | 6b42381685595c34f21d5ce9ef1c31ceac76720d (diff) | |
download | gcc-1fc2a7fe7e2351e560e75a0a17960816728aa419.zip gcc-1fc2a7fe7e2351e560e75a0a17960816728aa419.tar.gz gcc-1fc2a7fe7e2351e560e75a0a17960816728aa419.tar.bz2 |
Stop shadowing of hir mappings with substitution mappings
Name shadowing in C++ is annoying, it can cause subtle errors like here,
the mappings which are substitition mappings, for example from an impl
block, impl<X,Y> Foo(X), the type resolver here looks for any unconstrained
type parameters by passing the relative mappings which can be null. Since
the util mappings class shadowed this we never actually got this hidden
nullptr segv. For QualifiedTypes we need to resolve the path similar to
path expressions and we will need to be able to access the shadowed util
hir mappings class.
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-type.h | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.h b/gcc/rust/typecheck/rust-hir-type-check-type.h index 0cc1cfb..15eab25 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-type.h +++ b/gcc/rust/typecheck/rust-hir-type-check-type.h @@ -60,9 +60,10 @@ class TypeCheckType : public TypeCheckBase public: static TyTy::BaseType * Resolve (HIR::Type *type, - std::vector<TyTy::SubstitutionParamMapping> *mappings = nullptr) + std::vector<TyTy::SubstitutionParamMapping> *subst_mappings + = nullptr) { - TypeCheckType resolver (mappings); + TypeCheckType resolver (subst_mappings); type->accept_vis (resolver); if (resolver.translated == nullptr) @@ -210,8 +211,8 @@ public: } private: - TypeCheckType (std::vector<TyTy::SubstitutionParamMapping> *mappings) - : TypeCheckBase (), mappings (mappings), translated (nullptr) + TypeCheckType (std::vector<TyTy::SubstitutionParamMapping> *subst_mappings) + : TypeCheckBase (), subst_mappings (subst_mappings), translated (nullptr) {} void @@ -219,11 +220,15 @@ private: { std::map<std::string, Location> param_location_map; std::set<std::string> param_tys; - for (auto &mapping : *mappings) + + if (subst_mappings != nullptr) { - std::string sym = mapping.get_param_ty ()->get_symbol (); - param_tys.insert (sym); - param_location_map[sym] = mapping.get_generic_param ().get_locus (); + for (auto &mapping : *subst_mappings) + { + std::string sym = mapping.get_param_ty ()->get_symbol (); + param_tys.insert (sym); + param_location_map[sym] = mapping.get_generic_param ().get_locus (); + } } std::set<std::string> args; @@ -241,7 +246,7 @@ private: } } - std::vector<TyTy::SubstitutionParamMapping> *mappings; + std::vector<TyTy::SubstitutionParamMapping> *subst_mappings; TyTy::BaseType *translated; }; |