fix segfault on polymorphic arguments when no arguments are expected - #7140
fix segfault on polymorphic arguments when no arguments are expected#7140edizeqiri wants to merge 2 commits into
Conversation
|
can you confirm your patch also keeps the intended error message for a type assignment? e.g. so your output should look like |
The current output does not emit that error: ./odin run -file debug/test.odin
/Users/edi/Documents/GitHub/Odin/debug/test.odin(1:1) Error: Undefined entry point procedure 'main'
package main
^
/Users/edi/Documents/GitHub/Odin/debug/test.odin(7:3) Error: Invalid parameter type
components: ArchetypeRow
^~~~~~~~~~~~~~~~~~~~~~~^
/Users/edi/Documents/GitHub/Odin/debug/test.odin(7:15) Error: Invalid use of a non-specialized polymorphic type 'ArchetypeRow'
components: ArchetypeRow
^~~~~~~~~~~^
/Users/edi/Documents/GitHub/Odin/debug/test.odin(13:23) Error: Undeclared name: Entity
spawn :: proc(entity: Entity) {
^~~~~^
/Users/edi/Documents/GitHub/Odin/debug/test.odin(14:16) Error: Type 'Archetype' does not expect any polymorphic parameters
archetype := Archetype(entity)
^~~~~~~~~~~~~~~~^
/Users/edi/Documents/GitHub/Odin/debug/test.odin(19:9) Error: Cannot assign value 'player' of type 'Player' to 'invalid type' in a procedure argument
spawn(player)
^~~~~^While debugging I found out that the error you mentioned would be in check_decl.cpp:60. But when debugging it never went past the first if condition. if (operand->mode == Addressing_Type) {
if (e->type != nullptr && is_type_typeid(e->type) && !is_type_polymorphic(operand->type)) {
add_type_info_type(ctx, operand->type);
add_type_and_value(ctx, operand->expr, Addressing_Value, e->type, exact_value_typeid(operand->type));
return e->type;
} else {
ERROR_BLOCK();
gbString t = type_to_string(operand->type);
defer (gb_string_free(t));
if (is_type_polymorphic(operand->type)) {
error(operand->expr, "Cannot assign a non-specialized polymorphic type '%s' to variable '%.*s'", t, LIT(e->token.string));
} else {
error(operand->expr, "Cannot assign a type '%s' to variable '%.*s'", t, LIT(e->token.string));
}
if (e->type == nullptr) {
error_line("\tThe type of the variable '%.*s' cannot be inferred as a type and does not have a default type\n", LIT(e->token.string));
}
e->type = operand->type;
return nullptr;
}
}I do not think that my patch is causing this to not show the error, but I am not certain. What do you think? |
antisaling
left a comment
There was a problem hiding this comment.
So your patch causes check_call_expr_as_type_cast to poison the operand. I'm not completely sure on what's the clear path here to preserve the second error because check_call_expr_as_type_cast would need to be smarter about "recoverable" errors.
LGTM?
|
After this gets merged, I could open an issue for |
Hi, I've been learning Odin and trying to build an ECS with it and stumbled upon a segfault while compiling my code.
Bug
output:
This happens with the latest release and main.
Fix
Since I would like to contribute in the future, I tried to find and fix the error in the compiler.
From my understanding, the problem lies in the struct 'Archetype' which should have a generic input like 'ArcheTypeRow' and which the compiler expects, but the naive user (me) forgot it in the struct definition but not in the initialization of it.
This is the following error message the user now gets:
.../bug.odin(14:16) Error: No params are expected! archetype := Archetype(entity) ^~~~~~~~~~~~~~~~^