authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-22 14:26:45-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2018-02-22 14:26:45-05:00
logb66547e98c9034e52c5647735b47dc24939c8d15
treeb84792ffb976bdad957943043b86c515d8905ad4
parent884b5fb4cfa81fba863f24cf5c6d9d7c2a21d11f
parent0845cbe27783486feb5b4b57b2839326a2c86a6b
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #783 from bnoordhuis/fix675

name types inside functions after variable

3 files changed, 27 insertions(+), 6 deletions(-)

src/ir.cpp+6
......@@ -4172,7 +4172,13 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
41724172 buf_sprintf("cannot set section of local variable '%s'", buf_ptr(variable_declaration->symbol)));
41734173 }
41744174
4175 // Temporarily set the name of the IrExecutable to the VariableDeclaration
4176 // so that the struct or enum from the init expression inherits the name.
4177 Buf *old_exec_name = irb->exec->name;
4178 irb->exec->name = variable_declaration->symbol;
41754179 IrInstruction *init_value = ir_gen_node(irb, variable_declaration->expr, scope);
4180 irb->exec->name = old_exec_name;
4181
41764182 if (init_value == irb->codegen->invalid_instruction)
41774183 return init_value;
41784184
std/fmt/index.zig+4-6
......@@ -550,12 +550,6 @@ test "parse unsigned comptime" {
550550 }
551551}
552552
553// Dummy field because of https://github.com/zig-lang/zig/issues/557.
554// At top level because of https://github.com/zig-lang/zig/issues/675.
555const Struct = struct {
556 unused: u8,
557};
558
559553test "fmt.format" {
560554 {
561555 var buf1: [32]u8 = undefined;
......@@ -588,6 +582,10 @@ test "fmt.format" {
588582 assert(mem.eql(u8, result, "u3: 5\n"));
589583 }
590584 {
585 // Dummy field because of https://github.com/zig-lang/zig/issues/557.
586 const Struct = struct {
587 unused: u8,
588 };
591589 var buf1: [32]u8 = undefined;
592590 const value = Struct {
593591 .unused = 42,
test/cases/misc.zig+17
......@@ -499,12 +499,29 @@ test "@canImplicitCast" {
499499}
500500
501501test "@typeName" {
502 const Struct = struct {
503 };
504 const Union = union {
505 unused: u8,
506 };
507 const Enum = enum {
508 Unused,
509 };
502510 comptime {
503511 assert(mem.eql(u8, @typeName(i64), "i64"));
504512 assert(mem.eql(u8, @typeName(&usize), "&usize"));
513 // https://github.com/zig-lang/zig/issues/675
514 assert(mem.eql(u8, @typeName(TypeFromFn(u8)), "TypeFromFn(u8)"));
515 assert(mem.eql(u8, @typeName(Struct), "Struct"));
516 assert(mem.eql(u8, @typeName(Union), "Union"));
517 assert(mem.eql(u8, @typeName(Enum), "Enum"));
505518 }
506519}
507520
521fn TypeFromFn(comptime T: type) type {
522 return struct {};
523}
524
508525test "volatile load and store" {
509526 var number: i32 = 1234;
510527 const ptr = (&volatile i32)(&number);