self-hosted: add compile error test for missing fn name

This commit is contained in:
Andrew Kelley 2018-07-11 01:26:46 -04:00
parent c620a1fe3d
commit c6c49389eb
2 changed files with 8 additions and 7 deletions

View File

@ -347,13 +347,10 @@ pub const Module = struct {
const fn_proto = @fieldParentPtr(ast.Node.FnProto, "base", decl); const fn_proto = @fieldParentPtr(ast.Node.FnProto, "base", decl);
const name = if (fn_proto.name_token) |name_token| tree.tokenSlice(name_token) else { const name = if (fn_proto.name_token) |name_token| tree.tokenSlice(name_token) else {
@panic("TODO add compile error"); try self.addCompileError(parsed_file, errmsg.Span{
//try self.addCompileError( .first = fn_proto.fn_token,
// parsed_file, .last = fn_proto.fn_token + 1,
// fn_proto.fn_token, }, "missing function name");
// fn_proto.fn_token + 1,
// "missing function name",
//);
continue; continue;
}; };

View File

@ -17,6 +17,10 @@ test "compile errors" {
\\export fn entry() void {} \\export fn entry() void {}
, file1, 2, 8, "exported symbol collision: 'entry'"); , file1, 2, 8, "exported symbol collision: 'entry'");
try ctx.testCompileError(
\\fn() void {}
, file1, 1, 1, "missing function name");
try ctx.run(); try ctx.run();
} }