part of constuctor typecheck (constructors for different types)

This commit is contained in:
ProgramSnail 2024-02-22 21:57:54 +03:00
parent 005fb6aaf3
commit d7f1b6c377
3 changed files with 217 additions and 59 deletions

View file

@ -177,9 +177,10 @@ inline std::optional<size_t> get_parameters_count(Type type) {
return std::nullopt;
case Type::ARRAY:
case Type::OPTIONAL:
case Type::RESULT:
case Type::ERROR:
return 1;
case Type::RESULT: // RESULT[T E] = T | Error[E]
return 2;
// -- basic types
case Type::FLOAT:
case Type::DOUBLE:

View file

@ -243,6 +243,21 @@ public:
std::move(parameters)));
}
TypeProxy add_error_of(TypeProxy type, Node node = Node()) {
if (type.type_storage_ != this) {
error_handling::handle_general_error(
"TypeStorage: Can't add error of type from another type "
"storage");
}
std::vector<nodes::TypeProxy> parameters;
parameters.push_back(type);
return add_type(Type(Identifier(node, Identifier::SIMPLE_TYPE,
builtin::types::ERROR_IDENTIFIER),
std::move(parameters)));
}
nodes::TypeProxy add_container_of(std::vector<TypeProxy> &&parameters,
builtin::types::Type container,
Node node = Node()) {