1111#include " Luau/ModuleResolver.h"
1212#include " Luau/Normalize.h"
1313#include " Luau/NotNull.h"
14+ #include " Luau/Polarity.h"
1415#include " Luau/Refinement.h"
1516#include " Luau/Symbol.h"
1617#include " Luau/TypeFwd.h"
1718#include " Luau/TypeUtils.h"
18- #include " Luau/Variant.h"
1919
2020#include < memory>
2121#include < vector>
22- #include < unordered_map>
2322
2423namespace Luau
2524{
@@ -162,19 +161,26 @@ struct ConstraintGenerator
162161 void visitFragmentRoot (const ScopePtr& resumeScope, AstStatBlock* block);
163162
164163private:
165- std::vector<std::vector<TypeId>> interiorTypes;
164+ struct InteriorFreeTypes
165+ {
166+ std::vector<TypeId> types;
167+ std::vector<TypePackId> typePacks;
168+ };
169+
170+ std::vector<std::vector<TypeId>> DEPRECATED_interiorTypes;
171+ std::vector<InteriorFreeTypes> interiorFreeTypes;
166172
167173 /* *
168174 * Fabricates a new free type belonging to a given scope.
169175 * @param scope the scope the free type belongs to.
170176 */
171- TypeId freshType (const ScopePtr& scope);
177+ TypeId freshType (const ScopePtr& scope, Polarity polarity = Polarity::Unknown );
172178
173179 /* *
174180 * Fabricates a new free type pack belonging to a given scope.
175181 * @param scope the scope the free type pack belongs to.
176182 */
177- TypePackId freshTypePack (const ScopePtr& scope);
183+ TypePackId freshTypePack (const ScopePtr& scope, Polarity polarity = Polarity::Unknown );
178184
179185 /* *
180186 * Allocate a new TypePack with the given head and tail.
@@ -295,7 +301,7 @@ struct ConstraintGenerator
295301 );
296302
297303 Inference check (const ScopePtr& scope, AstExprConstantString* string, std::optional<TypeId> expectedType, bool forceSingleton);
298- Inference check (const ScopePtr& scope, AstExprConstantBool* bool_ , std::optional<TypeId> expectedType, bool forceSingleton);
304+ Inference check (const ScopePtr& scope, AstExprConstantBool* boolExpr , std::optional<TypeId> expectedType, bool forceSingleton);
299305 Inference check (const ScopePtr& scope, AstExprLocal* local);
300306 Inference check (const ScopePtr& scope, AstExprGlobal* global);
301307 Inference checkIndexName (const ScopePtr& scope, const RefinementKey* key, AstExpr* indexee, const std::string& index, Location indexLocation);
@@ -371,6 +377,11 @@ struct ConstraintGenerator
371377 **/
372378 TypeId resolveType (const ScopePtr& scope, AstType* ty, bool inTypeArguments, bool replaceErrorWithFresh = false );
373379
380+ // resolveType() is recursive, but we only want to invoke
381+ // inferGenericPolarities() once at the very end. We thus isolate the
382+ // recursive part of the algorithm to this internal helper.
383+ TypeId resolveType_ (const ScopePtr& scope, AstType* ty, bool inTypeArguments, bool replaceErrorWithFresh = false );
384+
374385 /* *
375386 * Resolves a type pack from its AST annotation.
376387 * @param scope the scope that the type annotation appears within.
@@ -380,6 +391,9 @@ struct ConstraintGenerator
380391 **/
381392 TypePackId resolveTypePack (const ScopePtr& scope, AstTypePack* tp, bool inTypeArguments, bool replaceErrorWithFresh = false );
382393
394+ // Inner hepler for resolveTypePack
395+ TypePackId resolveTypePack_ (const ScopePtr& scope, AstTypePack* tp, bool inTypeArguments, bool replaceErrorWithFresh = false );
396+
383397 /* *
384398 * Resolves a type pack from its AST annotation.
385399 * @param scope the scope that the type annotation appears within.
@@ -418,7 +432,7 @@ struct ConstraintGenerator
418432 **/
419433 std::vector<std::pair<Name, GenericTypePackDefinition>> createGenericPacks (
420434 const ScopePtr& scope,
421- AstArray<AstGenericTypePack*> packs ,
435+ AstArray<AstGenericTypePack*> generics ,
422436 bool useCache = false ,
423437 bool addTypes = true
424438 );
0 commit comments