2022-05-06 08:03:43 +08:00
|
|
|
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
|
|
|
|
|
|
#include "Fixture.h"
|
|
|
|
|
|
|
|
#include "Luau/RecursionCounter.h"
|
|
|
|
|
|
|
|
#include "doctest.h"
|
|
|
|
|
|
|
|
using namespace Luau;
|
|
|
|
|
2023-09-23 03:12:15 +08:00
|
|
|
LUAU_FASTINT(LuauVisitRecursionLimit);
|
2024-08-31 04:16:51 +08:00
|
|
|
LUAU_FASTFLAG(LuauSolverV2)
|
2022-05-06 08:03:43 +08:00
|
|
|
|
2023-09-23 03:12:15 +08:00
|
|
|
TEST_SUITE_BEGIN("VisitType");
|
2022-05-06 08:03:43 +08:00
|
|
|
|
2022-06-24 09:56:00 +08:00
|
|
|
TEST_CASE_FIXTURE(Fixture, "throw_when_limit_is_exceeded")
|
2022-05-06 08:03:43 +08:00
|
|
|
{
|
2024-08-31 04:16:51 +08:00
|
|
|
if (FFlag::LuauSolverV2)
|
2024-08-24 00:35:30 +08:00
|
|
|
{
|
|
|
|
CheckResult result = check(R"(
|
|
|
|
local t : {a: {b: {c: {d: {e: boolean}}}}}
|
|
|
|
)");
|
|
|
|
ScopedFastInt sfi{FInt::LuauVisitRecursionLimit, 3};
|
|
|
|
TypeId tType = requireType("t");
|
|
|
|
|
|
|
|
CHECK_THROWS_AS(toString(tType), RecursionLimitException);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ScopedFastInt sfi{FInt::LuauVisitRecursionLimit, 3};
|
|
|
|
|
|
|
|
CheckResult result = check(R"(
|
|
|
|
local t : {a: {b: {c: {d: {e: boolean}}}}}
|
|
|
|
)");
|
|
|
|
|
|
|
|
TypeId tType = requireType("t");
|
|
|
|
|
|
|
|
CHECK_THROWS_AS(toString(tType), RecursionLimitException);
|
|
|
|
}
|
2022-05-06 08:03:43 +08:00
|
|
|
}
|
|
|
|
|
2022-06-24 09:56:00 +08:00
|
|
|
TEST_CASE_FIXTURE(Fixture, "dont_throw_when_limit_is_high_enough")
|
2022-05-06 08:03:43 +08:00
|
|
|
{
|
2023-12-02 15:46:57 +08:00
|
|
|
ScopedFastInt sfi{FInt::LuauVisitRecursionLimit, 8};
|
2022-05-06 08:03:43 +08:00
|
|
|
|
|
|
|
CheckResult result = check(R"(
|
|
|
|
local t : {a: {b: {c: {d: {e: boolean}}}}}
|
|
|
|
)");
|
|
|
|
|
|
|
|
TypeId tType = requireType("t");
|
|
|
|
|
|
|
|
(void)toString(tType);
|
|
|
|
}
|
|
|
|
|
2023-09-23 03:12:15 +08:00
|
|
|
TEST_CASE_FIXTURE(Fixture, "some_free_types_do_not_have_bounds")
|
|
|
|
{
|
|
|
|
Type t{FreeType{TypeLevel{}}};
|
|
|
|
|
|
|
|
(void)toString(&t);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(Fixture, "some_free_types_have_bounds")
|
|
|
|
{
|
2024-08-31 04:16:51 +08:00
|
|
|
ScopedFastFlag sff{FFlag::LuauSolverV2, true};
|
2023-09-23 03:12:15 +08:00
|
|
|
|
|
|
|
Scope scope{builtinTypes->anyTypePack};
|
|
|
|
Type t{FreeType{&scope, builtinTypes->neverType, builtinTypes->numberType}};
|
|
|
|
|
|
|
|
CHECK("('a <: number)" == toString(&t));
|
|
|
|
}
|
|
|
|
|
2022-05-06 08:03:43 +08:00
|
|
|
TEST_SUITE_END();
|