luau/tests/TypeInfer.rwprops.test.cpp
vegorov-rbx 271c509046
Sync to upstream/release/578 (#939)
* Fixed gcc warning about uninitialized `std::optional`
* Fixed inlining of functions when they are used to compute their own
arguments

In the new type solver:
* Type families that are not part of a function signature cannot be
resolved at instantiation time and will now produce an error. This will
be relaxed in the future when we get constraint clauses on function
signatures (internally)
* `never` type is now comparable
* Improved typechecking of `for..in` statements
* Fixed checks for number type in `Add` type family
* Performance was improved, with particularly large gains on large
projects

And in native code generation (jit):
* We eliminated the call instruction overhead when native code support
is enabled in the VM
* Small optimizations to arm64 lowering
* Reworked LOP_GETIMPORT handling to reduce assembly code size
* Fixed non-deterministic binary output
* Fixed bad code generation caused by incorrect SSA to VM register links
invalidation

---------

Co-authored-by: Arseny Kapoulkine <arseny.kapoulkine@gmail.com>
Co-authored-by: Andy Friesen <afriesen@roblox.com>
2023-05-25 14:36:34 -07:00

71 lines
1.6 KiB
C++

// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
#include "Fixture.h"
#include "doctest.h"
LUAU_FASTFLAG(DebugLuauReadWriteProperties)
using namespace Luau;
namespace
{
struct ReadWriteFixture : Fixture
{
ScopedFastFlag dcr{"DebugLuauDeferredConstraintResolution", true};
ReadWriteFixture()
: Fixture()
{
if (!FFlag::DebugLuauReadWriteProperties)
return;
TypeArena* arena = &frontend.globals.globalTypes;
NotNull<Scope> globalScope{frontend.globals.globalScope.get()};
unfreeze(*arena);
TypeId genericT = arena->addType(GenericType{"T"});
TypeId readonlyX = arena->addType(TableType{TableState::Sealed, TypeLevel{}, globalScope});
getMutable<TableType>(readonlyX)->props["x"] = Property::readonly(genericT);
globalScope->addBuiltinTypeBinding("ReadonlyX", TypeFun{{{genericT}}, readonlyX});
freeze(*arena);
}
};
} // namespace
TEST_SUITE_BEGIN("ReadWriteProperties");
TEST_CASE_FIXTURE(ReadWriteFixture, "read_from_a_readonly_prop")
{
if (!FFlag::DebugLuauReadWriteProperties)
return;
CheckResult result = check(R"(
function f(rx: ReadonlyX<string>)
local x = rx.x
end
)");
LUAU_REQUIRE_NO_ERRORS(result);
}
TEST_CASE_FIXTURE(ReadWriteFixture, "write_to_a_readonly_prop")
{
if (!FFlag::DebugLuauReadWriteProperties)
return;
CheckResult result = check(R"(
function f(rx: ReadonlyX<string>)
rx.x = "hello!" -- error
end
)");
LUAU_REQUIRE_ERROR_COUNT(1, result);
}
TEST_SUITE_END();