Skip to content

Commit

Permalink
Fix exception when raising type mismatch on function argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainan committed Jun 27, 2024
1 parent 835c8a7 commit d040f11
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/lparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
std::string TypeDesc::toString() const {
std::string str = vtToString(type);
if (type == VT_FUNC &&
retn &&
!retn->empty()) {
str.push_back('(');
str.append(retn->toString());
Expand Down
2 changes: 1 addition & 1 deletion src/lparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ struct TypeDesc {

/* function info */
Proto* proto = nullptr;
TypeHint* retn;
TypeHint* retn = nullptr;
static constexpr int MAX_TYPED_PARAMS = 10;
TypeHint* params[MAX_TYPED_PARAMS];
bool nodiscard = false;
Expand Down
6 changes: 6 additions & 0 deletions testes/pluto/basic.pluto
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ do
local a = f()
end

-- Another possible exception here
assert_warn([[
local function delegator(f: function) end
delegator()
]])

assert_warn([[local a = 69; local b: string = a]]) -- type mismatch in local-to-local assignment
assert_warn([[g = 69; local l: string = g]]) -- type mismatch in global-to-local assignment

Expand Down

0 comments on commit d040f11

Please sign in to comment.