Description
In ezc/src/codegen/codegen.c, the resolve_print_suffix() function determines which print variant (_str, _int, _float, etc.) to emit for a given argument. When the argument is a struct-scoped function call (e.g. MyStruct.some_method()), there's an unfinished branch at lines 2076-2080 that enters but does nothing:
if (codegen_is_enum(cg, obj) || (obj[0] >= 'A' && obj[0] <= 'Z')) {
(void)mem; /* TODO: proper return type lookup */
}
It falls through to return "_int" at line 2088, meaning any struct function call whose return type isn't already in the typetable gets printed as an integer.
Steps to Reproduce
Call println() with a struct-scoped function that returns a string, in a context where the typetable doesn't have the return type recorded:
const Foo struct {
name string
do greet() -> string {
return "hello"
}
}
do main() {
mut f = Foo{name: "test"}
println(f.greet())
}
If the typetable resolves the return type, this works. If it doesn't (edge case), the codegen emits ez_builtin_println_int instead of ez_builtin_println_str.
Expected Behavior
resolve_print_suffix() should look up the struct function's return type from the forward declarations or function signature when the typetable doesn't have it.
Affected Code
ezc/src/codegen/codegen.c lines 2076-2080 (resolve_print_suffix())
Description
In
ezc/src/codegen/codegen.c, theresolve_print_suffix()function determines which print variant (_str,_int,_float, etc.) to emit for a given argument. When the argument is a struct-scoped function call (e.g.MyStruct.some_method()), there's an unfinished branch at lines 2076-2080 that enters but does nothing:It falls through to
return "_int"at line 2088, meaning any struct function call whose return type isn't already in the typetable gets printed as an integer.Steps to Reproduce
Call
println()with a struct-scoped function that returns a string, in a context where the typetable doesn't have the return type recorded:If the typetable resolves the return type, this works. If it doesn't (edge case), the codegen emits
ez_builtin_println_intinstead ofez_builtin_println_str.Expected Behavior
resolve_print_suffix()should look up the struct function's return type from the forward declarations or function signature when the typetable doesn't have it.Affected Code
ezc/src/codegen/codegen.clines 2076-2080 (resolve_print_suffix())