Skip to content

stage2: detect ambiguous decl references #8921

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

Merged
merged 1 commit into from
Jun 8, 2021

Conversation

g-w1
Copy link
Contributor

@g-w1 g-w1 commented May 28, 2021

This also found some compile errors in std, so I fixed them.
Putting this as a separate pr as my work on unused vars as #8920 is blocking that, but not this.

@g-w1
Copy link
Contributor Author

g-w1 commented May 28, 2021

I think this does not compile because of a stage1 scoping bug? I just fixed the compile errors in a different way.

@g-w1 g-w1 force-pushed the superpower-astgen branch 2 times, most recently from d94013e to c488cc7 Compare May 28, 2021 18:04
@g-w1 g-w1 force-pushed the superpower-astgen branch 2 times, most recently from 9eaaa85 to 5848850 Compare June 1, 2021 01:23
std: fix compile errors from this change. This is a stage1 bug.
@g-w1 g-w1 force-pushed the superpower-astgen branch from 5848850 to 5ba6d75 Compare June 1, 2021 01:24
@@ -5347,6 +5349,7 @@ fn forExpr(
.name = index_name,
.ptr = index_ptr,
.token_src = index_token,
.is_comptime = parent_gz.force_comptime,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this correct?

Copy link
Member

Choose a reason for hiding this comment

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

This should use is_inline since the index is also comptime known for inline loops. Also sorry for not answering sooner.

Copy link
Member

Choose a reason for hiding this comment

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

Btw @andrewrk, @SpexGuy What should the correct behavior be for

pub fn main() void {
    comptime var i = 0;
    inline while (i < 5) : (i+=1) {
        const S = struct {
            fn print() void {
                std.debug.print("loop {d}\n", .{i});
            }
        };
        S.print();
    }
}

Stage1 prints

loop 5
loop 5
loop 5
loop 5
loop 5

but I think most people would assume it to print

loop 0
loop 1
loop 2
loop 3
loop 4

@andrewrk andrewrk merged commit b57ac48 into ziglang:master Jun 8, 2021
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.

3 participants