2023-09-30 02:13:05 +01:00
|
|
|
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
|
|
#include "Luau/NonStrictTypeChecker.h"
|
|
|
|
|
|
|
|
#include "Fixture.h"
|
|
|
|
|
2023-10-06 20:02:32 +01:00
|
|
|
#include "Luau/Common.h"
|
|
|
|
#include "Luau/Ast.h"
|
|
|
|
#include "Luau/ModuleResolver.h"
|
|
|
|
#include "ScopedFlags.h"
|
2023-09-30 02:13:05 +01:00
|
|
|
#include "doctest.h"
|
2023-10-06 20:02:32 +01:00
|
|
|
#include <iostream>
|
2023-09-30 02:13:05 +01:00
|
|
|
|
|
|
|
using namespace Luau;
|
|
|
|
|
2023-10-06 20:02:32 +01:00
|
|
|
struct NonStrictTypeCheckerFixture : Fixture
|
|
|
|
{
|
|
|
|
|
2023-10-13 21:20:12 +01:00
|
|
|
CheckResult checkNonStrict(const std::string& code)
|
2023-10-06 20:02:32 +01:00
|
|
|
{
|
2023-10-13 21:20:12 +01:00
|
|
|
ScopedFastFlag flags[] = {
|
|
|
|
{"LuauCheckedFunctionSyntax", true},
|
2023-10-21 02:10:30 +01:00
|
|
|
{"DebugLuauDeferredConstraintResolution", true},
|
2023-10-13 21:20:12 +01:00
|
|
|
};
|
2023-10-21 02:10:30 +01:00
|
|
|
LoadDefinitionFileResult res = loadDefinition(definitions);
|
|
|
|
LUAU_ASSERT(res.success);
|
2023-10-13 21:20:12 +01:00
|
|
|
return check(Mode::Nonstrict, code);
|
|
|
|
}
|
2023-09-30 02:13:05 +01:00
|
|
|
|
2023-10-13 21:20:12 +01:00
|
|
|
std::string definitions = R"BUILTIN_SRC(
|
2023-10-06 20:02:32 +01:00
|
|
|
declare function @checked abs(n: number): number
|
|
|
|
)BUILTIN_SRC";
|
2023-10-13 21:20:12 +01:00
|
|
|
};
|
2023-10-06 20:02:32 +01:00
|
|
|
|
|
|
|
|
2023-10-13 21:20:12 +01:00
|
|
|
TEST_SUITE_BEGIN("NonStrictTypeCheckerTest");
|
2023-10-06 20:02:32 +01:00
|
|
|
|
2023-10-13 21:20:12 +01:00
|
|
|
TEST_CASE_FIXTURE(NonStrictTypeCheckerFixture, "simple_non_strict")
|
2023-10-06 20:02:32 +01:00
|
|
|
{
|
2023-10-13 21:20:12 +01:00
|
|
|
auto res = checkNonStrict(R"BUILTIN_SRC(
|
|
|
|
abs("hi")
|
|
|
|
)BUILTIN_SRC");
|
2023-10-21 02:10:30 +01:00
|
|
|
LUAU_REQUIRE_ERRORS(res);
|
|
|
|
REQUIRE(res.errors.size() == 1);
|
|
|
|
auto err = get<CheckedFunctionCallError>(res.errors[0]);
|
|
|
|
REQUIRE(err != nullptr);
|
|
|
|
REQUIRE(err->checkedFunctionName == "abs");
|
2023-10-06 20:02:32 +01:00
|
|
|
}
|
|
|
|
|
2023-09-30 02:13:05 +01:00
|
|
|
TEST_SUITE_END();
|