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

AstGen: missing compile error for return inside defer expression #8820

Closed
andrewrk opened this issue May 18, 2021 · 0 comments · Fixed by #8848
Closed

AstGen: missing compile error for return inside defer expression #8820

andrewrk opened this issue May 18, 2021 · 0 comments · Fixed by #8848
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@andrewrk
Copy link
Member

extern fn bar() void;

export fn foo() void {
    defer bar();
    defer return;
}

stage1 gives the correct result:

./test.zig:5:11: error: cannot return from defer expression
    defer return;
          ^

stage2 does not catch the problem. It should be caught in AstGen:

[nix-shell:~/dev/zig/build-release]$ ./zig-out/bin/zig astgen test.zig
# Source bytes:       83B
# Tokens:             24 (144B)
# AST Nodes:          12 (276B)
# Total ZIR bytes:    414B
# Instructions:       16 (144B)
# String Table Bytes: 10B
# Extra Data Items:   49 (196B)
%15 = extended(struct_decl(parent, Auto, {
  [35] bar line(0) hash(a136708cffc080900b4d0ec55ba4898f): %0 = block_inline({
    %1 = extended(func([], @Ref.void_type, cc=@Ref.calling_convention_c, extern, {}) node_offset:1:8
    %2 = break_inline(%0, %1)
  }) node_offset:1:8
  [42] export foo line(2) hash(29d6f5fbb9c6edc9aaf52cebc6e0ab46): %3 = block_inline({
    %13 = func([], @Ref.void_type, {
      %4 = dbg_stmt(2, 10)
      %5 = dbg_stmt(1, 10)
      %6 = decl_val("bar") token_offset:4:11
      %7 = call_chkused(%6, []) node_offset:4:14
      %8 = ret_node(@Ref.void_value) node_offset:5:11
      %9 = dbg_stmt(1, 10)
      %10 = decl_val("bar") token_offset:4:11
      %11 = call_chkused(%10, []) node_offset:4:14
      %12 = ret_coerce(@Ref.void_value) token_offset:6:1
    }) (lbrace=0:21,rbrace=3:0) node_offset:3:8
    %14 = break_inline(%3, %13)
  }) node_offset:3:8
}, {}, {})
@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness. labels May 18, 2021
@andrewrk andrewrk added this to the 0.8.0 milestone May 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant