From 0845cbe27783486feb5b4b57b2839326a2c86a6b Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 22 Feb 2018 17:53:58 +0100 Subject: name types inside functions after variable Before this commit: fn f() []const u8 { const S = struct {}; return @typeName(S); // "f()", unexpected. } And now: fn f() []const u8 { const S = struct {}; return @typeName(S); // "S", expected. } Fixes #675. --- src/ir.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/ir.cpp') diff --git a/src/ir.cpp b/src/ir.cpp index 7eac9e4d23..b276abff33 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -4172,7 +4172,13 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod buf_sprintf("cannot set section of local variable '%s'", buf_ptr(variable_declaration->symbol))); } + // Temporarily set the name of the IrExecutable to the VariableDeclaration + // so that the struct or enum from the init expression inherits the name. + Buf *old_exec_name = irb->exec->name; + irb->exec->name = variable_declaration->symbol; IrInstruction *init_value = ir_gen_node(irb, variable_declaration->expr, scope); + irb->exec->name = old_exec_name; + if (init_value == irb->codegen->invalid_instruction) return init_value; -- cgit v1.2.3