authorgravatar for me@paperdave.netdave caruso <me@paperdave.net> 2024-09-16 17:03:36-07:00
committergravatar for me@paperdave.netdave caruso <me@paperdave.net> 2024-09-16 17:03:36-07:00
logb0c173910c8131298d9cc74335843fdcf91d4225
tree7cdfdd0f18964d7ec3dede0032c73430e90412e4
parent4470c3b285523251143a844ca7821d457fdae8af
signature Commit is signed but in an unrecognized format.

feat: allow any expression as a function body


5 files changed, 7 insertions(+), 5 deletions(-)

CHANGELOG.md+2
......@@ -1,5 +1,7 @@
11## 0.1.7
22
3- feat: allow any expression as a function body
4
35## 0.1.6
46
57- breaking: rename `@js` to `@extern`, considering future backends
src/cli_compiler.zig+2
......@@ -48,6 +48,8 @@ pub fn main() !u8 {
4848 defer Cli.programArgsFree(alloc, args);
4949 const opts = arg_config.parse(program_name, args);
5050
51 if (opts.report_trace == true) Report.debug_show_report_trace = true;
52
5153 const file_path = try std.fs.path.resolve(alloc, &.{
5254 cwd,
5355 opts.positionals orelse
src/core/Parse.zig+1-2
......@@ -498,8 +498,7 @@ fn parseFnDecl(p: *Parse) Error!NodeIndex {
498498 else
499499 null;
500500
501 try p.expectWithoutAdvance(.start_brace);
502 const body = try p.parseBlock();
501 const body = try p.parseExpression(.expression);
503502
504503 const extra = try p.addExtra(Ast.Fn, .{
505504 .params = params orelse .empty,
src/core/Sema.zig+1-1
......@@ -1706,7 +1706,7 @@ fn coerceRef(s: *Sema, src: LazyNode, ref: Air.Inst.Ref, to: Type) !Air.Inst.Ref
17061706 },
17071707 .int32 => switch (from) {
17081708 .int32 => unreachable, // same type handled
1709 .numeric_literal => unreachable, // must should comptime known
1709 .numeric_literal => unreachable, // must be comptime known
17101710 else => {},
17111711 },
17121712 .float => switch (from) {
test/behavior/inferred_return_type+1-2
......@@ -1,8 +1,7 @@
11let assertEqual = @extern("assertEqual");
22
3fn getString() {
3fn getString()
44 "hello"
5}
65
76fn main {
87 let str = getString();