mirror of
https://github.com/luau-lang/luau.git
synced 2024-11-15 14:25:44 +08:00
Sync to upstream/release/513 (#342)
This commit is contained in:
parent
d58e70b8c1
commit
e51ff38d19
@ -346,7 +346,8 @@ private:
|
|||||||
|
|
||||||
// Note: `scope` must be a fresh scope.
|
// Note: `scope` must be a fresh scope.
|
||||||
GenericTypeDefinitions createGenericTypes(const ScopePtr& scope, std::optional<TypeLevel> levelOpt, const AstNode& node,
|
GenericTypeDefinitions createGenericTypes(const ScopePtr& scope, std::optional<TypeLevel> levelOpt, const AstNode& node,
|
||||||
const AstArray<AstGenericType>& genericNames, const AstArray<AstGenericTypePack>& genericPackNames);
|
const AstArray<AstGenericType>& genericNames, const AstArray<AstGenericTypePack>& genericPackNames,
|
||||||
|
bool useCache = false);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ErrorVec resolve(const PredicateVec& predicates, const ScopePtr& scope, bool sense);
|
ErrorVec resolve(const PredicateVec& predicates, const ScopePtr& scope, bool sense);
|
||||||
|
@ -29,6 +29,7 @@ LUAU_FASTFLAGVARIABLE(LuauWeakEqConstraint, false) // Eventually removed as fals
|
|||||||
LUAU_FASTFLAG(LuauUseCommittingTxnLog)
|
LUAU_FASTFLAG(LuauUseCommittingTxnLog)
|
||||||
LUAU_FASTFLAGVARIABLE(DebugLuauFreezeDuringUnification, false)
|
LUAU_FASTFLAGVARIABLE(DebugLuauFreezeDuringUnification, false)
|
||||||
LUAU_FASTFLAGVARIABLE(LuauRecursiveTypeParameterRestriction, false)
|
LUAU_FASTFLAGVARIABLE(LuauRecursiveTypeParameterRestriction, false)
|
||||||
|
LUAU_FASTFLAGVARIABLE(LuauGenericFunctionsDontCacheTypeParams, false)
|
||||||
LUAU_FASTFLAGVARIABLE(LuauIfElseBranchTypeUnion, false)
|
LUAU_FASTFLAGVARIABLE(LuauIfElseBranchTypeUnion, false)
|
||||||
LUAU_FASTFLAGVARIABLE(LuauIfElseExpectedType2, false)
|
LUAU_FASTFLAGVARIABLE(LuauIfElseExpectedType2, false)
|
||||||
LUAU_FASTFLAGVARIABLE(LuauLengthOnCompositeType, false)
|
LUAU_FASTFLAGVARIABLE(LuauLengthOnCompositeType, false)
|
||||||
@ -1199,7 +1200,7 @@ void TypeChecker::check(const ScopePtr& scope, const AstStatTypeAlias& typealias
|
|||||||
if (FFlag::LuauProperTypeLevels)
|
if (FFlag::LuauProperTypeLevels)
|
||||||
aliasScope->level.subLevel = subLevel;
|
aliasScope->level.subLevel = subLevel;
|
||||||
|
|
||||||
auto [generics, genericPacks] = createGenericTypes(aliasScope, scope->level, typealias, typealias.generics, typealias.genericPacks);
|
auto [generics, genericPacks] = createGenericTypes(aliasScope, scope->level, typealias, typealias.generics, typealias.genericPacks, /* useCache = */ true);
|
||||||
|
|
||||||
TypeId ty = freshType(aliasScope);
|
TypeId ty = freshType(aliasScope);
|
||||||
FreeTypeVar* ftv = getMutable<FreeTypeVar>(ty);
|
FreeTypeVar* ftv = getMutable<FreeTypeVar>(ty);
|
||||||
@ -5362,7 +5363,7 @@ TypeId TypeChecker::instantiateTypeFun(const ScopePtr& scope, const TypeFun& tf,
|
|||||||
}
|
}
|
||||||
|
|
||||||
GenericTypeDefinitions TypeChecker::createGenericTypes(const ScopePtr& scope, std::optional<TypeLevel> levelOpt, const AstNode& node,
|
GenericTypeDefinitions TypeChecker::createGenericTypes(const ScopePtr& scope, std::optional<TypeLevel> levelOpt, const AstNode& node,
|
||||||
const AstArray<AstGenericType>& genericNames, const AstArray<AstGenericTypePack>& genericPackNames)
|
const AstArray<AstGenericType>& genericNames, const AstArray<AstGenericTypePack>& genericPackNames, bool useCache)
|
||||||
{
|
{
|
||||||
LUAU_ASSERT(scope->parent);
|
LUAU_ASSERT(scope->parent);
|
||||||
|
|
||||||
@ -5388,7 +5389,7 @@ GenericTypeDefinitions TypeChecker::createGenericTypes(const ScopePtr& scope, st
|
|||||||
}
|
}
|
||||||
|
|
||||||
TypeId g;
|
TypeId g;
|
||||||
if (FFlag::LuauRecursiveTypeParameterRestriction)
|
if (FFlag::LuauRecursiveTypeParameterRestriction && (!FFlag::LuauGenericFunctionsDontCacheTypeParams || useCache))
|
||||||
{
|
{
|
||||||
TypeId& cached = scope->parent->typeAliasTypeParameters[n];
|
TypeId& cached = scope->parent->typeAliasTypeParameters[n];
|
||||||
if (!cached)
|
if (!cached)
|
||||||
|
@ -673,4 +673,29 @@ local d: D = c
|
|||||||
R"(Type '() -> ()' could not be converted into '<T...>() -> ()'; different number of generic type pack parameters)");
|
R"(Type '() -> ()' could not be converted into '<T...>() -> ()'; different number of generic type pack parameters)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE_FIXTURE(Fixture, "generic_functions_dont_cache_type_parameters")
|
||||||
|
{
|
||||||
|
ScopedFastFlag sff{"LuauGenericFunctionsDontCacheTypeParams", true};
|
||||||
|
|
||||||
|
CheckResult result = check(R"(
|
||||||
|
-- See https://github.com/Roblox/luau/issues/332
|
||||||
|
-- This function has a type parameter with the same name as clones,
|
||||||
|
-- so if we cache type parameter names for functions these get confused.
|
||||||
|
-- function id<Z>(x : Z) : Z
|
||||||
|
function id<X>(x : X) : X
|
||||||
|
return x
|
||||||
|
end
|
||||||
|
|
||||||
|
function clone<X, Y>(dict: {[X]:Y}): {[X]:Y}
|
||||||
|
local copy = {}
|
||||||
|
for k, v in pairs(dict) do
|
||||||
|
copy[k] = v
|
||||||
|
end
|
||||||
|
return copy
|
||||||
|
end
|
||||||
|
)");
|
||||||
|
|
||||||
|
LUAU_REQUIRE_NO_ERRORS(result);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_SUITE_END();
|
TEST_SUITE_END();
|
||||||
|
Loading…
Reference in New Issue
Block a user