Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error reporting the wrong line for struct field inits #13502

Merged
merged 3 commits into from
Nov 15, 2022

Conversation

mparadinha
Copy link
Contributor

@mparadinha mparadinha commented Nov 9, 2022

fixes #12752

Before:

parada@sendai ~/r/zig (master)> cat -n error.zig 
     1	const Data = struct {
     2	   p: *u32 = null,
     3	};
     4	
     5	pub fn main() void {
     6	   const d = Data{};
     7	   _ = d;
     8	}
parada@sendai ~/r/zig (master)> zig run error.zig
error.zig:1:14: error: expected type '*u32', found '@TypeOf(null)'
const Data = struct {
             ^~~~~~
referenced by:
    Data: error.zig:1:14
    main: error.zig:6:15
    remaining reference traces hidden; use '-freference-trace' to see all reference traces

Afer:

parada@sendai ~/r/zig (12752)> zig run error.zig
bug_smaller.zig:2:15: error: expected type '*u32', found '@TypeOf(null)'
    p: *u32 = null,
              ^~~~
referenced by:
    Data: bug_smaller.zig:1:14
    main: bug_smaller.zig:6:15
    remaining reference traces hidden; use '-freference-trace' to see all reference traces

src/Sema.zig Outdated Show resolved Hide resolved
src/Sema.zig Outdated
Comment on lines 29793 to 29794
const default_val = sema.resolveMaybeUndefVal(&block_scope, .unneeded, coerced) catch |err| switch (err) {
error.NeededSourceLocation => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing this check for resolveMaybeUndefVal isn't very useful but it should be done before the call to failWithNeededComptime.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you prefer I wait a bit until #13532 gets merged, and then fix this and rebase?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is going to be merge conflicts either way so it doesn't really matter though I'll probably want Andrews opinion on that change so this might be able to get merged first.

@mparadinha
Copy link
Contributor Author

Didn't have access to my dev machine until now.
Ended up rebasing on master, because #13532 got merged in the meantime.

@Vexu Vexu merged commit c4f7663 into ziglang:master Nov 15, 2022
@mparadinha mparadinha deleted the 12752 branch November 15, 2022 14:52
@andrewrk andrewrk added this to the 0.10.1 milestone Jan 9, 2023
andrewrk pushed a commit that referenced this pull request Jan 9, 2023
* point to init part of field delc when that's where the error occurs

* update test to reflect fixed error message

* only lookup source location in case of error
TUSF pushed a commit to TUSF/zig that referenced this pull request May 9, 2024
)

* point to init part of field delc when that's where the error occurs

* update test to reflect fixed error message

* only lookup source location in case of error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error message points to wrong line
3 participants