Skip to content

Commit 0b380c5

Browse files
authored
Check main has no parameters after args (#725)
* Refactor with local var * Check main has no parameters after `args`
1 parent 387d352 commit 0b380c5

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

source/sema.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,17 +1341,19 @@ class sema
13411341
)
13421342
{
13431343
auto& func = std::get<declaration_node::a_function>(n.type);
1344+
auto& params = func->parameters->parameters;
13441345

13451346
// It's more readable to express this as positive condition here...
13461347
if (
13471348
// There are no parameters
1348-
func->parameters->parameters.empty()
1349+
params.empty()
13491350
// Or there's a single wildcard in-param named 'args'
13501351
|| (
1351-
func->parameters->parameters[0]->has_name("args")
1352-
&& func->parameters->parameters[0]->pass == passing_style::in
1353-
&& func->parameters->parameters[0]->declaration->is_object()
1354-
&& std::get<declaration_node::an_object>(func->parameters->parameters[0]->declaration->type)->is_wildcard()
1352+
params.size() == 1
1353+
&& params[0]->has_name("args")
1354+
&& params[0]->pass == passing_style::in
1355+
&& params[0]->declaration->is_object()
1356+
&& std::get<declaration_node::an_object>(params[0]->declaration->type)->is_wildcard()
13551357
)
13561358
)
13571359
{
@@ -1361,7 +1363,7 @@ class sema
13611363
else
13621364
{
13631365
errors.emplace_back(
1364-
func->parameters->parameters[0]->position(),
1366+
params[0]->position(),
13651367
"'main' must be declared as 'main: ()' with zero parameters, or 'main: (args)' with one parameter named 'args' for which the type 'std::vector<std::string_view>' will be deduced"
13661368
);
13671369
return false;

0 commit comments

Comments
 (0)