Contract on trying to use Object without initializing it.

This commit is contained in:
Christoffer Lerno
2025-05-14 23:22:34 +02:00
parent 36eb650228
commit 511ae0da00
2 changed files with 5 additions and 1 deletions

View File

@@ -186,6 +186,9 @@ fn void Object.set_object(&self, String key, Object* new_object) @private
self.map.set(key, new_object); self.map.set(key, new_object);
} }
<*
@require self.allocator != null : "This object is not properly initialized, was it really created using 'new'"
*>
macro Object* Object.object_from_value(&self, value) @private macro Object* Object.object_from_value(&self, value) @private
{ {
var $Type = $typeof(value); var $Type = $typeof(value);
@@ -201,7 +204,7 @@ macro Object* Object.object_from_value(&self, value) @private
$case $Type.typeid == Object*.typeid: $case $Type.typeid == Object*.typeid:
return value; return value;
$case $Type.typeid == void*.typeid: $case $Type.typeid == void*.typeid:
if (value != null) return TYPE_MISMATCH?; if (value != null) TYPE_MISMATCH?!;
return &NULL_OBJECT; return &NULL_OBJECT;
$case $assignable(value, String): $case $assignable(value, String):
return new_string(value, self.allocator); return new_string(value, self.allocator);

View File

@@ -16,6 +16,7 @@
- Fix regression in Time diff due to operator overloading #2124. - Fix regression in Time diff due to operator overloading #2124.
- attrdef with any invalid name causes compiler assert #2128. - attrdef with any invalid name causes compiler assert #2128.
- Correctly error on `@attrdef Foo = ;`. - Correctly error on `@attrdef Foo = ;`.
- Contract on trying to use Object without initializing it.
### Stdlib changes ### Stdlib changes
- Added `String.quick_ztr` and `String.is_zstr` - Added `String.quick_ztr` and `String.is_zstr`