aboutsummaryrefslogtreecommitdiff
path: root/boot
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2026-07-15 23:19:58 +0200
committerEugen Wissner <belka@caraus.de>2026-07-15 23:50:57 +0200
commitd0a666507a6f11b65170c257fd483613f462f3f2 (patch)
tree1a23edf414234defbb1b6a36aadcf3e7795e24dc /boot
parente7265af15f77abf60a899b3d53a59652b5ca71ea (diff)
downloadelna-d0a666507a6f11b65170c257fd483613f462f3f2.tar.gz
Use build3(COND_EXPR) for conditionals
Diffstat (limited to 'boot')
-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
{