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);
}
<*
@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
{
var $Type = $typeof(value);
@@ -201,7 +204,7 @@ macro Object* Object.object_from_value(&self, value) @private
$case $Type.typeid == Object*.typeid:
return value;
$case $Type.typeid == void*.typeid:
if (value != null) return TYPE_MISMATCH?;
if (value != null) TYPE_MISMATCH?!;
return &NULL_OBJECT;
$case $assignable(value, String):
return new_string(value, self.allocator);