mirror of
https://codeberg.org/ProgramSnail/lang.git
synced 2025-12-06 06:58:46 +00:00
type check error function
This commit is contained in:
parent
61fa3a19a0
commit
1a9408c2f6
4 changed files with 83 additions and 84 deletions
|
|
@ -186,7 +186,8 @@ private:
|
|||
class ContextHolder {
|
||||
public:
|
||||
ContextHolder(State &state, const nodes::Node &node,
|
||||
error_handling::ErrorLog &error_log, nodes::MaybeTypeProxy* context_exit_type)
|
||||
error_handling::ErrorLog &error_log,
|
||||
nodes::MaybeTypeProxy *context_exit_type)
|
||||
: state_(state), context_exit_type_(context_exit_type) {
|
||||
state.enter_context(node, error_log);
|
||||
}
|
||||
|
|
@ -198,16 +199,16 @@ public:
|
|||
ContextHolder &operator=(ContextHolder &&) = delete;
|
||||
|
||||
~ContextHolder() {
|
||||
if (context_exit_type_) {
|
||||
*context_exit_type_ = state_.exit_context();
|
||||
} else {
|
||||
state_.exit_context();
|
||||
}
|
||||
if (context_exit_type_) {
|
||||
*context_exit_type_ = state_.exit_context();
|
||||
} else {
|
||||
state_.exit_context();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
State &state_;
|
||||
nodes::MaybeTypeProxy* context_exit_type_;
|
||||
nodes::MaybeTypeProxy *context_exit_type_;
|
||||
};
|
||||
|
||||
nodes::TypeCheckResult type_same_to_expected(
|
||||
|
|
@ -225,4 +226,7 @@ find_name_definition_handle_errors(const std::string &name,
|
|||
const nodes::Node &node,
|
||||
SourcesManager &sources_manager);
|
||||
|
||||
void type_check_error(const std::string &message, const nodes::Node &node,
|
||||
SourcesManager &sources_manager);
|
||||
|
||||
} // namespace type_check
|
||||
|
|
|
|||
|
|
@ -11,3 +11,19 @@ inline void handle_general_error(const std::string &message) {
|
|||
}
|
||||
|
||||
} // namespace error_handling
|
||||
|
||||
namespace utils {
|
||||
|
||||
// in std from c++23
|
||||
[[noreturn]] inline void unreachable() {
|
||||
// Uses compiler specific extensions if possible.
|
||||
// Even if no extension is used, undefined behavior is still raised by
|
||||
// an empty function body and the noreturn attribute.
|
||||
#if defined(_MSC_VER) && !defined(__clang__) // MSVC
|
||||
__assume(false);
|
||||
#else // GCC, Clang
|
||||
__builtin_unreachable();
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace utils
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue