- Add contract on any_to_enum_ordinal and any_to_int to improve error when passed an empty any. #2977

This commit is contained in:
Christoffer Lerno
2026-02-26 22:31:00 +01:00
parent 54ddc9a81c
commit 596e550882
3 changed files with 6 additions and 1 deletions

View File

@@ -317,6 +317,9 @@ macro any.retype_to(&self, typeid type)
return $$any_make(self.ptr, type); return $$any_make(self.ptr, type);
} }
<*
@require (bool)self.type : "A typed any was expected"
*>
macro any.as_inner(&self) macro any.as_inner(&self)
{ {
return $$any_make(self.ptr, self.type.inner); return $$any_make(self.ptr, self.type.inner);

View File

@@ -7,6 +7,7 @@ faultdef VALUE_OUT_OF_RANGE, VALUE_OUT_OF_UNSIGNED_RANGE;
<* <*
@require $Type.kindof.is_int() : "Type was not an integer" @require $Type.kindof.is_int() : "Type was not an integer"
@require (bool)v.type : "The value was empty"
@require v.type.kindof == ENUM : "Value was not an enum" @require v.type.kindof == ENUM : "Value was not an enum"
*> *>
macro any_to_enum_ordinal(any v, $Type) macro any_to_enum_ordinal(any v, $Type)
@@ -16,6 +17,7 @@ macro any_to_enum_ordinal(any v, $Type)
<* <*
@require $Type.kindof.is_int() : "Type was not an integer" @require $Type.kindof.is_int() : "Type was not an integer"
@require (bool)v.type : "The value was empty"
@require v.type.kindof.is_int() : "Value was not an integer" @require v.type.kindof.is_int() : "Value was not an integer"
*> *>
macro any_to_int(any v, $Type) macro any_to_int(any v, $Type)

View File

@@ -6,7 +6,7 @@
- Removed support for LLVM 17, 18. - Removed support for LLVM 17, 18.
### Stdlib changes ### Stdlib changes
None - Add contract on `any_to_enum_ordinal` and `any_to_int` to improve error when passed an empty any. #2977
### Fixes ### Fixes
None None