luau/tests/Instantiation2.test.cpp
vegorov-rbx 9c2146288d
Sync to upstream/release/621 (#1229)
# What's changed?

* Support for new 'require by string' RFC with relative paths and
aliases in now enabled in Luau REPL application

### New Type Solver

* Fixed assertion failure on generic table keys (`[expr] = value`)
* Fixed an issue with type substitution traversing into the substituted
parts during type instantiation
* Fixed crash in union simplification when that union contained
uninhabited unions and other types inside
* Union types in binary type families like `add<a | b, c>` are expanded
into `add<a, c> | add<b, c>` to handle
* Added handling for type family solving creating new type families
* Fixed a bug with normalization operation caching types with unsolved
parts
* Tables with uninhabited properties are now simplified to `never`
* Fixed failures found by fuzzer

### Native Code Generation

* Added support for shared code generation between multiple Luau VM
instances
* Fixed issue in load-store propagation and new tagged LOAD_TVALUE
instructions
* Fixed issues with partial register dead store elimination causing
failures in GC assists

---

### Internal Contributors

Co-authored-by: Aaron Weiss <aaronweiss@roblox.com>
Co-authored-by: Alexander McCord <amccord@roblox.com>
Co-authored-by: Andy Friesen <afriesen@roblox.com>
Co-authored-by: James McNellis <jmcnellis@roblox.com>
Co-authored-by: Vighnesh Vijay <vvijay@roblox.com>
Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com>
2024-04-12 10:18:49 -07:00

54 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 "Luau/Instantiation2.h"
#include "Fixture.h"
#include "ClassFixture.h"
#include "ScopedFlags.h"
#include "doctest.h"
using namespace Luau;
TEST_SUITE_BEGIN("Instantiation2Test");
TEST_CASE_FIXTURE(Fixture, "weird_cyclic_instantiation")
{
TypeArena arena;
Scope scope(builtinTypes->anyTypePack);
TypeId genericT = arena.addType(GenericType{"T"});
TypeId idTy = arena.addType(FunctionType{
/* generics */ {genericT},
/* genericPacks */ {},
/* argTypes */ arena.addTypePack({genericT}),
/* retTypes */ arena.addTypePack({genericT})
});
DenseHashMap<TypeId, TypeId> genericSubstitutions{nullptr};
DenseHashMap<TypePackId, TypePackId> genericPackSubstitutions{nullptr};
TypeId freeTy = arena.freshType(&scope);
FreeType* ft = getMutable<FreeType>(freeTy);
REQUIRE(ft);
ft->lowerBound = idTy;
ft->upperBound = builtinTypes->unknownType;
genericSubstitutions[genericT] = freeTy;
CHECK("<T>(T) -> T" == toString(idTy));
std::optional<TypeId> res = instantiate2(&arena, std::move(genericSubstitutions), std::move(genericPackSubstitutions), idTy);
// Substitutions should not mutate the original type!
CHECK("<T>(T) -> T" == toString(idTy));
// Weird looking because we haven't properly clipped the generic from the
// function type, but this is what we asked for.
REQUIRE(res);
CHECK("<<T>(T) -> T>(<T>(T) -> T) -> <T>(T) -> T" == toString(*res));
}
TEST_SUITE_END();