Add locations to error reporting.

This commit is contained in:
2020-09-09 15:08:43 -07:00
parent 2fa2be4b9e
commit aa867b2e5f
3 changed files with 40 additions and 13 deletions

View File

@@ -1,21 +1,30 @@
#pragma once
#include <exception>
#include <optional>
#include "type.hpp"
#include "location.hh"
#include "parse_driver.hpp"
using maybe_location = std::optional<yy::location>;
struct type_error : std::exception {
std::string description;
std::optional<yy::location> loc;
type_error(std::string d)
: description(std::move(d)) {}
type_error(std::string d, maybe_location l = std::nullopt)
: description(std::move(d)), loc(std::move(l)) {}
const char* what() const noexcept override;
void pretty_print(std::ostream& to, parse_driver& drv);
};
struct unification_error : public type_error {
type_ptr left;
type_ptr right;
unification_error(type_ptr l, type_ptr r)
unification_error(type_ptr l, type_ptr r, maybe_location loc = std::nullopt)
: left(std::move(l)), right(std::move(r)),
type_error("failed to unify types") {}
type_error("failed to unify types", std::move(loc)) {}
void pretty_print(std::ostream& to, parse_driver& drv, type_mgr& mgr);
};