diff --git a/code/compiler/13/parsed_type.cpp b/code/compiler/13/parsed_type.cpp index d119509..2fa31ee 100644 --- a/code/compiler/13/parsed_type.cpp +++ b/code/compiler/13/parsed_type.cpp @@ -9,10 +9,10 @@ type_ptr parsed_type_app::to_type( const type_env& e) const { auto parent_type = e.lookup_type(name); if(parent_type == nullptr) - throw type_error(std::string("no such type or type constructor ") + name); + throw type_error("no such type or type constructor " + name); type_base* base_type; if(!(base_type = dynamic_cast(parent_type.get()))) - throw type_error(std::string("invalid type ") + name); + throw type_error("invalid type " + name); if(base_type->arity != arguments.size()) { std::ostringstream error_stream; error_stream << "invalid application of type "; @@ -34,7 +34,7 @@ type_ptr parsed_type_var::to_type( const std::set& vars, const type_env& e) const { if(vars.find(var) == vars.end()) - throw type_error(std::string("the type variable ") + var + std::string(" was not explicitly declared.")); + throw type_error("the type variable " + var + " was not explicitly declared."); return type_ptr(new type_var(var)); } diff --git a/code/compiler/13/type_env.cpp b/code/compiler/13/type_env.cpp index 0c0ddef..47a5212 100644 --- a/code/compiler/13/type_env.cpp +++ b/code/compiler/13/type_env.cpp @@ -1,6 +1,7 @@ #include "type_env.hpp" #include "type.hpp" #include "error.hpp" +#include void type_env::find_free(const type_mgr& mgr, std::set& into) const { if(parent != nullptr) parent->find_free(mgr, into); @@ -45,7 +46,10 @@ void type_env::set_mangled_name(const std::string& name, const std::string& mang const std::string& type_env::get_mangled_name(const std::string& name) const { auto it = names.find(name); - if(it != names.end()) return it->second.mangled_name; + if(it != names.end()) { + assert(it->second.mangled_name); + return *it->second.mangled_name; + } assert(parent != nullptr); return parent->get_mangled_name(name); } @@ -59,7 +63,7 @@ type_ptr type_env::lookup_type(const std::string& name) const { void type_env::bind(const std::string& name, type_ptr t, visibility v) { type_scheme_ptr new_scheme(new type_scheme(std::move(t))); - names[name] = variable_data(std::move(new_scheme), v, ""); + names[name] = variable_data(std::move(new_scheme), v, std::nullopt); } void type_env::bind(const std::string& name, type_scheme_ptr t, visibility v) { diff --git a/code/compiler/13/type_env.hpp b/code/compiler/13/type_env.hpp index f5d98ed..2bc3450 100644 --- a/code/compiler/13/type_env.hpp +++ b/code/compiler/13/type_env.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "graph.hpp" #include "type.hpp" @@ -15,11 +16,11 @@ class type_env { struct variable_data { type_scheme_ptr type; visibility vis; - std::string mangled_name; + std::optional mangled_name; variable_data() - : variable_data(nullptr, visibility::local, "") {} - variable_data(type_scheme_ptr t, visibility v, std::string n) + : variable_data(nullptr, visibility::local, std::nullopt) {} + variable_data(type_scheme_ptr t, visibility v, std::optional n) : type(std::move(t)), vis(v), mangled_name(std::move(n)) {} };