aboutsummaryrefslogtreecommitdiff
path: root/boot/semantic.cc
diff options
context:
space:
mode:
Diffstat (limited to 'boot/semantic.cc')
-rw-r--r--boot/semantic.cc31
1 files changed, 31 insertions, 0 deletions
diff --git a/boot/semantic.cc b/boot/semantic.cc
index 031adfc..9137053 100644
--- a/boot/semantic.cc
+++ b/boot/semantic.cc
@@ -206,6 +206,18 @@ namespace elna::boot
}
}
+ unsupported_trait_type_error::unsupported_trait_type_error(const identifier& trait,
+ type actual)
+ : error(trait.position()), trait_name(trait.name()), actual(actual)
+ {
+ }
+
+ std::string unsupported_trait_type_error::what() const
+ {
+ return "Type '" + actual.to_string()
+ + "' does not support trait '#" + trait_name + "'";
+ }
+
type_analysis_visitor::type_analysis_visitor(symbol_bag bag)
: error_container(), bag(bag)
{
@@ -917,6 +929,25 @@ namespace elna::boot
else if (trait->name == "min" || trait->name == "max")
{
trait->type_decoration = trait->types.empty() ? type() : trait->types.front();
+
+ if (!trait->type_decoration.empty())
+ {
+ type resolved = inner_aliased_type(trait->type_decoration);
+ bool is_enum = resolved.get<enumeration_type>() != nullptr;
+ bool is_integral = false;
+
+ if (auto prim = resolved.get<primitive_type>())
+ {
+ is_integral = prim->identifier == "Int" || prim->identifier == "Word"
+ || prim->identifier == "Bool" || prim->identifier == "Char";
+ }
+ if (!is_enum && !is_integral)
+ {
+ add_error<unsupported_trait_type_error>(trait->name,
+ trait->type_decoration);
+ trait->type_decoration = type();
+ }
+ }
}
else
{