Skip to content

Commit

Permalink
Allow nil as a default argument but raise bad-practice warning
Browse files Browse the repository at this point in the history
It is also handled as a no-op now.
  • Loading branch information
Sainan authored and well-in-that-case committed Jan 29, 2025
1 parent d068125 commit df9dd8b
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/lparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2151,13 +2151,16 @@ static void parlist (LexState *ls, std::vector<std::pair<TString*, TString*>>* p
if (fallbacks) {
if (testnext(ls, '=')) {
if (ls->t.token == TK_NIL) {
throwerr(ls, "default argument expected", "nil is not a valid default argument");
throw_warn(ls, "default arguments substitute nil values, not absent ones", "'= nil' is a no-op", WT_BAD_PRACTICE);
luaX_next(ls);
}
else {
fallbacks->emplace_back(luaX_getpos(ls));
if (lambda)
skip_over_simpleexp_within_lambdaparlist(ls);
else
skip_over_simpleexp_within_parenlist(ls);
}
fallbacks->emplace_back(luaX_getpos(ls));
if (lambda)
skip_over_simpleexp_within_lambdaparlist(ls);
else
skip_over_simpleexp_within_parenlist(ls);
}
else {
fallbacks->emplace_back(0);
Expand Down

0 comments on commit df9dd8b

Please sign in to comment.