compiler error improvement: assist if `foo.x` access doesn't exist, but a field/method/var `x` does exist on `foo`
Zig Version
0.10.0-dev.4476+0f0076666
Steps to Reproduce and Observed Behavior
var arena = std.heap.ArenaAllocator.init(testing.allocator);
defer arena.deinit();
const allocator = arena.allocator;
This code produces an error:
/Users/slimsag/Desktop/hexops/mach-examples/libs/mach/libs/earcut/src/main.zig:740:29: error: no field named 'allocator' in struct 'heap.arena_allocator.ArenaAllocator'
const allocator = arena.allocator;
^~~~~~~~~
Expected Behavior
The Zig compiler should be smart enough to see the error I made, and suggest (maybe you meant to call .allocator(...) ?) since the fixed code is:
var arena = std.heap.ArenaAllocator.init(testing.allocator);
defer arena.deinit();
- const allocator = arena.allocator;
+ const allocator = arena.allocator();
while this could be helpful, i think the error should stay as is. an argument could be made that the suggestion could potentially be useful as a note, but its better to have errors avoid guessing what the user meant to do. particularly since fields and declarations occupy separate namespaces, the context this note provides starts to become context dependent and less helpful.
imo this note would be better suited as an observation made by 3rd party tooling, such as a dev's editor
Re-opening because people are hitting into this in other cases: https://www.reddit.com/r/Zig/comments/146avyi/error_no_field_named_x_in_struct_y_despite_field/
Maybe it's not the compiler's job to tell users about this - but there should probably be some answer to this.