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 @@...@@ -1,5 +1,7 @@
1## 0.1.71## 0.1.7
22
3- feat: allow any expression as a function body
4
3## 0.1.65## 0.1.6
46
5- breaking: rename `@js` to `@extern`, considering future backends7- breaking: rename `@js` to `@extern`, considering future backends
src/cli_compiler.zig+2
...@@ -48,6 +48,8 @@ pub fn main() !u8 {...@@ -48,6 +48,8 @@ pub fn main() !u8 {
48 defer Cli.programArgsFree(alloc, args);48 defer Cli.programArgsFree(alloc, args);
49 const opts = arg_config.parse(program_name, args);49 const opts = arg_config.parse(program_name, args);
5050
51 if (opts.report_trace == true) Report.debug_show_report_trace = true;
52
51 const file_path = try std.fs.path.resolve(alloc, &.{53 const file_path = try std.fs.path.resolve(alloc, &.{
52 cwd,54 cwd,
53 opts.positionals orelse55 opts.positionals orelse
src/core/Parse.zig+1-2
...@@ -498,8 +498,7 @@ fn parseFnDecl(p: *Parse) Error!NodeIndex {...@@ -498,8 +498,7 @@ fn parseFnDecl(p: *Parse) Error!NodeIndex {
498 else498 else
499 null;499 null;
500500
501 try p.expectWithoutAdvance(.start_brace);501 const body = try p.parseExpression(.expression);
502 const body = try p.parseBlock();
503502
504 const extra = try p.addExtra(Ast.Fn, .{503 const extra = try p.addExtra(Ast.Fn, .{
505 .params = params orelse .empty,504 .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...@@ -1706,7 +1706,7 @@ fn coerceRef(s: *Sema, src: LazyNode, ref: Air.Inst.Ref, to: Type) !Air.Inst.Ref
1706 },1706 },
1707 .int32 => switch (from) {1707 .int32 => switch (from) {
1708 .int32 => unreachable, // same type handled1708 .int32 => unreachable, // same type handled
1709 .numeric_literal => unreachable, // must should comptime known1709 .numeric_literal => unreachable, // must be comptime known
1710 else => {},1710 else => {},
1711 },1711 },
1712 .float => switch (from) {1712 .float => switch (from) {
test/behavior/inferred_return_type+1-2
...@@ -1,8 +1,7 @@...@@ -1,8 +1,7 @@
1let assertEqual = @extern("assertEqual");1let assertEqual = @extern("assertEqual");
22
3fn getString() {3fn getString()
4 "hello"4 "hello"
5}
65
7fn main {6fn main {
8 let str = getString();7 let str = getString();