- Fix error message when a method has the wrong type for the first argument.

- Add `any.to` and `any.as`.
This commit is contained in:
Christoffer Lerno
2025-12-16 16:02:56 +01:00
parent 86a05ba6c0
commit e49e3e32e7
4 changed files with 30 additions and 4 deletions

View File

@@ -108,6 +108,25 @@ macro anycast(any v, $Type) @builtin
return ($Type*)v.ptr;
}
<*
@return "The value in the pointer"
@return? TYPE_MISMATCH
*>
macro any.as(self, $Type)
{
if (self.type != $Type.typeid) return TYPE_MISMATCH?;
return *($Type*)self.ptr;
}
<*
@require self.type == $Type : "The 'any' contained an unexpected type."
@return "The value in the pointer"
*>
macro any.to(self, $Type)
{
return *($Type*)self.ptr;
}
macro bool @assignable_to(#foo, $Type) @const @builtin @deprecated("use '$defined($Type x = #foo)'") => $defined(*&&($Type){} = #foo);
macro @addr(#val) @builtin