bloglang/13/error.cpp

29 lines
940 B
C++

#include "error.hpp"
const char* type_error::what() const noexcept {
return "an error occured while checking the types of the program";
}
void type_error::pretty_print(std::ostream& to, parse_driver& drv) {
to << "encountered error while typechecking program: ";
to << description << std::endl;
if(loc) {
to << "occuring on line " << loc->begin.line << ":" << std::endl;
to << std::endl << "```" << std::endl;
drv.print_highlighted_location(to, *loc);
to << "```" << std::endl << std::endl;
}
}
void unification_error::pretty_print(std::ostream& to, parse_driver& drv, type_mgr& mgr) {
type_error::pretty_print(to, drv);
to << "the expected type was:" << std::endl;
to << " \033[34m";
left->print(mgr, to);
to << std::endl << "\033[0mwhile the actual type was:" << std::endl;
to << " \033[32m";
right->print(mgr, to);
to << "\033[0m" << std::endl;
}