Skip to content

Commit

Permalink
Removes MismatchedError message for ignored return values
Browse files Browse the repository at this point in the history
  • Loading branch information
cipharius committed Nov 3, 2021
1 parent b18fd1c commit 4036db2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
10 changes: 4 additions & 6 deletions Analysis/src/Error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,10 @@ struct ErrorConverter
return "Expected to return " + std::to_string(e.expected) + " value" + expectedS + ", but " +
std::to_string(e.actual) + " " + actualVerb + " returned here";
case CountMismatch::Result:
if (e.expected > e.actual)
return "Function returns " + std::to_string(e.expected) + " values, but there " + actualVerb +
" only " + std::to_string(e.actual) + " value" + actualS + " to unpack into";
else
return "Function only returns " + std::to_string(e.expected) + " value" + expectedS + ". " +
std::to_string(e.actual) + " are required here";
// It is alright if right hand side produces more values than the
// left hand side accepts. In this context consider only the opposite case.
return "Function only returns " + std::to_string(e.expected) + " value" + expectedS + ". " +
std::to_string(e.actual) + " are required here";
case CountMismatch::Arg:
return "Argument count mismatch. Function " + wrongNumberOfArgsString(e.expected, e.actual);
}
Expand Down
10 changes: 2 additions & 8 deletions tests/TypeInfer.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3256,7 +3256,7 @@ TEST_CASE_FIXTURE(Fixture, "too_many_return_values")
CHECK_EQ(acm->actual, 2);
}

TEST_CASE_FIXTURE(Fixture, "not_enough_return_values")
TEST_CASE_FIXTURE(Fixture, "ignored_return_values")
{
CheckResult result = check(R"(
--!strict
Expand All @@ -3268,13 +3268,7 @@ TEST_CASE_FIXTURE(Fixture, "not_enough_return_values")
local a = f()
)");

LUAU_REQUIRE_ERROR_COUNT(1, result);

CountMismatch* acm = get<CountMismatch>(result.errors[0]);
REQUIRE(acm);
CHECK_EQ(acm->context, CountMismatch::Result);
CHECK_EQ(acm->expected, 2);
CHECK_EQ(acm->actual, 1);
LUAU_REQUIRE_ERROR_COUNT(0, result);
}

TEST_CASE_FIXTURE(Fixture, "function_does_not_return_enough_values")
Expand Down

0 comments on commit 4036db2

Please sign in to comment.