diff --git a/Analysis/include/Luau/TypeInfer.h b/Analysis/include/Luau/TypeInfer.h index 455654d9..dac2902c 100644 --- a/Analysis/include/Luau/TypeInfer.h +++ b/Analysis/include/Luau/TypeInfer.h @@ -345,6 +345,7 @@ private: TypePackId freshTypePack(TypeLevel level); TypeId resolveType(const ScopePtr& scope, const AstType& annotation); + TypeId resolveTypeWorker(const ScopePtr& scope, const AstType& annotation); TypePackId resolveTypePack(const ScopePtr& scope, const AstTypeList& types); TypePackId resolveTypePack(const ScopePtr& scope, const AstTypePack& annotation); TypeId instantiateTypeFun(const ScopePtr& scope, const TypeFun& tf, const std::vector& typeParams, diff --git a/Analysis/src/TypeInfer.cpp b/Analysis/src/TypeInfer.cpp index 1d6b0403..4fafb50f 100644 --- a/Analysis/src/TypeInfer.cpp +++ b/Analysis/src/TypeInfer.cpp @@ -4884,6 +4884,13 @@ TypePackId TypeChecker::freshTypePack(TypeLevel level) } TypeId TypeChecker::resolveType(const ScopePtr& scope, const AstType& annotation) +{ + TypeId ty = resolveTypeWorker(scope, annotation); + currentModule->astResolvedTypes[&annotation] = ty; + return ty; +} + +TypeId TypeChecker::resolveTypeWorker(const ScopePtr& scope, const AstType& annotation) { if (const auto& lit = annotation.as()) { @@ -4899,7 +4906,7 @@ TypeId TypeChecker::resolveType(const ScopePtr& scope, const AstType& annotation if (lit->parameters.size != 1 || !lit->parameters.data[0].type) { reportError(TypeError{annotation.location, GenericError{"_luau_print requires one generic parameter"}}); - return currentModule->astResolvedTypes[&annotation] = errorRecoveryType(anyType); + return errorRecoveryType(anyType); } ToStringOptions opts; @@ -4909,7 +4916,7 @@ TypeId TypeChecker::resolveType(const ScopePtr& scope, const AstType& annotation TypeId param = resolveType(scope, *lit->parameters.data[0].type); luauPrintLine(format("_luau_print\t%s\t|\t%s", toString(param, opts).c_str(), toString(lit->location).c_str())); - return currentModule->astResolvedTypes[&annotation] = param; + return param; } else @@ -4918,7 +4925,7 @@ TypeId TypeChecker::resolveType(const ScopePtr& scope, const AstType& annotation if (!tf) { if (lit->name == kParseNameError) - return currentModule->astResolvedTypes[&annotation] = errorRecoveryType(scope); + return errorRecoveryType(scope); std::string typeName; if (lit->prefix) @@ -4930,11 +4937,11 @@ TypeId TypeChecker::resolveType(const ScopePtr& scope, const AstType& annotation else reportError(TypeError{annotation.location, UnknownSymbol{typeName, UnknownSymbol::Type}}); - return currentModule->astResolvedTypes[&annotation] = errorRecoveryType(scope); + return errorRecoveryType(scope); } if (lit->parameters.size == 0 && tf->typeParams.empty() && tf->typePackParams.empty()) - return currentModule->astResolvedTypes[&annotation] = tf->type; + return tf->type; bool parameterCountErrorReported = false; bool hasDefaultTypes = std::any_of(tf->typeParams.begin(), tf->typeParams.end(), [](auto&& el) { @@ -5085,9 +5092,9 @@ TypeId TypeChecker::resolveType(const ScopePtr& scope, const AstType& annotation // If the generic parameters and the type arguments are the same, we are about to // perform an identity substitution, which we can just short-circuit. if (sameTys && sameTps) - return currentModule->astResolvedTypes[&annotation] = tf->type; + return tf->type; - return currentModule->astResolvedTypes[&annotation] = instantiateTypeFun(scope, *tf, typeParams, typePackParams, annotation.location); + return instantiateTypeFun(scope, *tf, typeParams, typePackParams, annotation.location); } else if (const auto& table = annotation.as()) { @@ -5102,7 +5109,7 @@ TypeId TypeChecker::resolveType(const ScopePtr& scope, const AstType& annotation TableTypeVar ttv{props, tableIndexer, scope->level, TableState::Sealed}; ttv.definitionModuleName = currentModuleName; - return currentModule->astResolvedTypes[&annotation] = addType(std::move(ttv)); + return addType(std::move(ttv)); } else if (const auto& func = annotation.as()) { @@ -5139,12 +5146,12 @@ TypeId TypeChecker::resolveType(const ScopePtr& scope, const AstType& annotation ftv->argNames.push_back(std::nullopt); } - return currentModule->astResolvedTypes[&annotation] = fnType; + return fnType; } else if (auto typeOf = annotation.as()) { TypeId ty = checkExpr(scope, *typeOf->expr).type; - return currentModule->astResolvedTypes[&annotation] = ty; + return ty; } else if (const auto& un = annotation.as()) { @@ -5152,7 +5159,7 @@ TypeId TypeChecker::resolveType(const ScopePtr& scope, const AstType& annotation for (AstType* ann : un->types) types.push_back(resolveType(scope, *ann)); - return currentModule->astResolvedTypes[&annotation] = addType(UnionTypeVar{types}); + return addType(UnionTypeVar{types}); } else if (const auto& un = annotation.as()) { @@ -5160,22 +5167,22 @@ TypeId TypeChecker::resolveType(const ScopePtr& scope, const AstType& annotation for (AstType* ann : un->types) types.push_back(resolveType(scope, *ann)); - return currentModule->astResolvedTypes[&annotation] = addType(IntersectionTypeVar{types}); + return addType(IntersectionTypeVar{types}); } else if (const auto& tsb = annotation.as()) { - return currentModule->astResolvedTypes[&annotation] = singletonType(tsb->value); + return singletonType(tsb->value); } else if (const auto& tss = annotation.as()) { - return currentModule->astResolvedTypes[&annotation] = singletonType(std::string(tss->value.data, tss->value.size)); + return singletonType(std::string(tss->value.data, tss->value.size)); } else if (annotation.is()) - return currentModule->astResolvedTypes[&annotation] = errorRecoveryType(scope); + return errorRecoveryType(scope); else { reportError(TypeError{annotation.location, GenericError{"Unknown type annotation?"}}); - return currentModule->astResolvedTypes[&annotation] = errorRecoveryType(scope); + return errorRecoveryType(scope); } }