Skip to content

Commit

Permalink
fix: Missing default would result in a null default value
Browse files Browse the repository at this point in the history
  • Loading branch information
giann committed May 21, 2024
1 parent ab7ed6a commit f446ef8
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/Parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2827,9 +2827,14 @@ fn parseFunctionType(self: *Self, parent_generic_types: ?std.AutoArrayHashMap(*o
self.reportErrorAtCurrent(.arguments_count, "Can't have more than 255 arguments.");
}

const arg_type = try self.parseTypeDef(merged_generic_types, true);
const arg_type = try self.parseTypeDef(
merged_generic_types,
true,
);
const arg_type_def = self.ast.nodes.items(.type_def)[arg_type];

try self.consume(.Identifier, "Expected argument name");

const arg_name_token = self.current_token.? - 1;
const arg_name = self.ast.tokens.items(.lexeme)[self.current_token.? - 1];

Expand Down Expand Up @@ -2864,13 +2869,12 @@ fn parseFunctionType(self: *Self, parent_generic_types: ?std.AutoArrayHashMap(*o
},
);

try defaults.put(
try self.gc.copyString(arg_name),
if (default) |def|
try self.ast.toValue(def, self.gc)
else
Value.Null,
);
if (default) |dflt| {
try defaults.put(
try self.gc.copyString(arg_name),
try self.ast.toValue(dflt, self.gc),
);
}
try parameters.put(try self.gc.copyString(arg_name), arg_type_def.?);

if (!try self.match(.Comma)) break;
Expand Down Expand Up @@ -5091,7 +5095,7 @@ fn function(
false,
argument_type,
true, // function arguments are constant
"Expected parameter name",
"Expected argument name",
);

std.debug.assert(self.current.?.scope_depth > 0);
Expand Down

0 comments on commit f446ef8

Please sign in to comment.