@@ -16,10 +16,11 @@ LUAU_FASTINTVARIABLE(LuauParseErrorLimit, 100)
1616// Warning: If you are introducing new syntax, ensure that it is behind a separate
1717// flag so that we don't break production games by reverting syntax changes.
1818// See docs/SyntaxChanges.md for an explanation.
19- LUAU_FASTFLAGVARIABLE(DebugLuauDeferredConstraintResolution , false )
19+ LUAU_FASTFLAGVARIABLE(LuauSolverV2 , false )
2020LUAU_FASTFLAGVARIABLE(LuauNativeAttribute, false )
2121LUAU_FASTFLAGVARIABLE(LuauAttributeSyntaxFunExpr, false )
22- LUAU_FASTFLAGVARIABLE(LuauUserDefinedTypeFunctions, false )
22+ LUAU_FASTFLAGVARIABLE(LuauUserDefinedTypeFunctionsSyntax2, false )
23+ LUAU_FASTFLAGVARIABLE(LuauAllowFragmentParsing, false )
2324
2425namespace Luau
2526{
@@ -211,6 +212,15 @@ Parser::Parser(const char* buffer, size_t bufferSize, AstNameTable& names, Alloc
211212 scratchExpr.reserve (16 );
212213 scratchLocal.reserve (16 );
213214 scratchBinding.reserve (16 );
215+
216+ if (FFlag::LuauAllowFragmentParsing)
217+ {
218+ if (options.parseFragment )
219+ {
220+ localMap = options.parseFragment ->localMap ;
221+ localStack = options.parseFragment ->localStack ;
222+ }
223+ }
214224}
215225
216226bool Parser::blockFollow (const Lexeme& l)
@@ -784,6 +794,7 @@ AstStat* Parser::parseAttributeStat()
784794 AstExpr* expr = parsePrimaryExpr (/* asStatement= */ true );
785795 return parseDeclaration (expr->location , attributes);
786796 }
797+ [[fallthrough]];
787798 default :
788799 return reportStatError (
789800 lexer.current ().location ,
@@ -890,10 +901,10 @@ AstStat* Parser::parseReturn()
890901AstStat* Parser::parseTypeAlias (const Location& start, bool exported)
891902{
892903 // parsing a type function
893- if (FFlag::LuauUserDefinedTypeFunctions )
904+ if (FFlag::LuauUserDefinedTypeFunctionsSyntax2 )
894905 {
895906 if (lexer.current ().type == Lexeme::ReservedFunction)
896- return parseTypeFunction (start);
907+ return parseTypeFunction (start, exported );
897908 }
898909
899910 // parsing a type alias
@@ -916,20 +927,28 @@ AstStat* Parser::parseTypeAlias(const Location& start, bool exported)
916927}
917928
918929// type function Name `(' arglist `)' `=' funcbody `end'
919- AstStat* Parser::parseTypeFunction (const Location& start)
930+ AstStat* Parser::parseTypeFunction (const Location& start, bool exported )
920931{
921932 Lexeme matchFn = lexer.current ();
922933 nextLexeme ();
923934
935+ if (exported)
936+ report (start, " Type function cannot be exported" );
937+
924938 // parse the name of the type function
925939 std::optional<Name> fnName = parseNameOpt (" type function name" );
926940 if (!fnName)
927941 fnName = Name (nameError, lexer.current ().location );
928942
929943 matchRecoveryStopOnToken[Lexeme::ReservedEnd]++;
930944
945+ size_t oldTypeFunctionDepth = typeFunctionDepth;
946+ typeFunctionDepth = functionStack.size ();
947+
931948 AstExprFunction* body = parseFunctionBody (/* hasself */ false , matchFn, fnName->name , nullptr , AstArray<AstAttr*>({nullptr , 0 })).first ;
932949
950+ typeFunctionDepth = oldTypeFunctionDepth;
951+
933952 matchRecoveryStopOnToken[Lexeme::ReservedEnd]--;
934953
935954 return allocator.alloc <AstStatTypeFunction>(Location (start, body->location ), fnName->name , fnName->location , body);
@@ -2280,6 +2299,12 @@ AstExpr* Parser::parseNameExpr(const char* context)
22802299 {
22812300 AstLocal* local = *value;
22822301
2302+ if (FFlag::LuauUserDefinedTypeFunctionsSyntax2)
2303+ {
2304+ if (local->functionDepth < typeFunctionDepth)
2305+ return reportExprError (lexer.current ().location , {}, " Type function cannot reference outer local '%s'" , local->name .value );
2306+ }
2307+
22832308 return allocator.alloc <AstExprLocal>(name->location , local, local->functionDepth != functionStack.size () - 1 );
22842309 }
22852310
0 commit comments