Least parsable, most common Error message

For users that like to bump into the type checker until we get it right (or more sincerely, those of us that learn from good error messages), the append procedure gives the most errors and the least actionable information (in my view).

I don’t know how much of this we should chalk up to skill issue versus investigating better errors. My mistake was to simply forget I was passing the array by value, not pointer, and then wondering why append didn’t like it.

If the error message just said “hey dummy gib pointer” I’d both have been on my way and learned not to make this mistake by now.

Error: No procedures or ambiguous call for procedure group 'append' that match with the given arguments 
	append(container, element) 
	^~~~~^ 
	Given argument types: ([dynamic]u8, u8) 
Did you mean to use one of the following: 
	runtime.append_elem        :: proc(array: ^$T/[dynamic]$E, #no_broadcast arg: E, loc := #caller_location) -> (n: int, err: Allocator_Error)        at /var/home/dev/Odin/base/runtime/core_builtin.odin(519:1) 
	runtime.append_elems       :: proc(array: ^$T/[dynamic]$E, #no_broadcast args: ..E, loc := #caller_location) -> (n: int, err: Allocator_Error)     at /var/home/dev/Odin/base/runtime/core_builtin.odin(568:1) 
	runtime.append_elem_string :: proc(array: ^$T/[dynamic]$E/u8, arg: $A/string, loc := #caller_location) -> (n: int, err: Allocator_Error)           at /var/home/dev/Odin/base/runtime/core_builtin.odin(595:1) 
	runtime.append_soa_elem    :: proc(array: ^$T/#soa[dynamic]$E, #no_broadcast arg: E, loc := #caller_location) -> (n: int, err: Allocator_Error)    at /var/home/dev/Odin/base/runtime/core_builtin_soa.odin(290:1) 
	runtime.append_soa_elems   :: proc(array: ^$T/#soa[dynamic]$E, #no_broadcast args: ..E, loc := #caller_location) -> (n: int, err: Allocator_Error) at /var/home/dev/Odin/base/runtime/core_builtin_soa.odin(347:1) 
3 Likes

While I agree that this should be improved, I have one advice: Don’t always use the overloads. Just type append_elem instead. The error message will be much more specific.

3 Likes

I think for this specific procedure, I need to improve the error message because it is brought up a lot. However, it is not an easy thing to solve in the general case.

4 Likes

I don’t know how everyone else feels about this, but for me, append wouldn’t even need the overload. When I type just append, I usually want append_elem and for all the others, I would probably type them out anyway because they feel more special. Changing that now would break a lot of code though I suppose.

Might not work as-is, but maybe the error message could tell you
" No procedure found by-value, did you mean to use by-pointer with &?"
But then you would still have the issue come up for proc group with some by-value and some by-pointer argument types :thinking:

For now, I’ve made a first naive PR that checks for append(), if that can already help new users: On wrong append call, help users pass-by-pointer by duchainer · Pull Request #5817 · odin-lang/Odin · GitHub