diff --git a/code/compiler/13/ast.cpp b/code/compiler/13/ast.cpp index 24e769a..efa84a4 100644 --- a/code/compiler/13/ast.cpp +++ b/code/compiler/13/ast.cpp @@ -340,7 +340,7 @@ struct case_strategy_data { std::vector& into) { env_ptr new_env = env; for(auto it = repr.second->rbegin(); it != repr.second->rend(); it++) { - new_env = env_ptr(new env_var(branch->expr->env->get_mangled_name(*it), new_env)); + new_env = env_ptr(new env_var(*it, new_env)); } into.push_back(instruction_ptr(new instruction_split(repr.second->size()))); @@ -392,7 +392,7 @@ void compile_case(const ast_case& node, const env_ptr& env, const type* type, st if(cases.defined_cases_count() == strategy.case_count(type)) throw type_error("redundant catch-all pattern", branch->pat->loc); auto& branch_into = cases.make_default_case(); - env_ptr new_env(new env_var(branch->expr->env->get_mangled_name(vpat->var), env)); + env_ptr new_env(new env_var(vpat->var, env)); branch->expr->compile(new_env, branch_into); branch_into.push_back(instruction_ptr(new instruction_slide(1))); } else { @@ -484,7 +484,7 @@ void ast_let::compile(const env_ptr& env, std::vector& into) co into.push_back(instruction_ptr(new instruction_alloc(translated_definitions.size()))); env_ptr new_env = env; for(auto& def : translated_definitions) { - new_env = env_ptr(new env_var(definitions.env->get_mangled_name(def.first), std::move(new_env))); + new_env = env_ptr(new env_var(def.first, std::move(new_env))); } int offset = translated_definitions.size() - 1; for(auto& def : translated_definitions) { diff --git a/code/compiler/13/type_env.cpp b/code/compiler/13/type_env.cpp index 4c5d3ad..5070f8c 100644 --- a/code/compiler/13/type_env.cpp +++ b/code/compiler/13/type_env.cpp @@ -34,7 +34,12 @@ bool type_env::is_global(const std::string& name) const { void type_env::set_mangled_name(const std::string& name, const std::string& mangled) { auto it = names.find(name); - if(it != names.end()) it->second.mangled_name = mangled; + if(it != names.end()) { + // Local names shouldn't need mangling. + assert(it->second.vis == visibility::global); + + it->second.mangled_name = mangled; + } } const std::string& type_env::get_mangled_name(const std::string& name) const {