@@ -16,10 +16,11 @@ LUAU_FASTINTVARIABLE(LuauParseErrorLimit, 100)
16
16
// Warning: If you are introducing new syntax, ensure that it is behind a separate
17
17
// flag so that we don't break production games by reverting syntax changes.
18
18
// See docs/SyntaxChanges.md for an explanation.
19
- LUAU_FASTFLAGVARIABLE(DebugLuauDeferredConstraintResolution , false )
19
+ LUAU_FASTFLAGVARIABLE(LuauSolverV2 , false )
20
20
LUAU_FASTFLAGVARIABLE(LuauNativeAttribute, false )
21
21
LUAU_FASTFLAGVARIABLE(LuauAttributeSyntaxFunExpr, false )
22
- LUAU_FASTFLAGVARIABLE(LuauUserDefinedTypeFunctions, false )
22
+ LUAU_FASTFLAGVARIABLE(LuauUserDefinedTypeFunctionsSyntax2, false )
23
+ LUAU_FASTFLAGVARIABLE(LuauAllowFragmentParsing, false )
23
24
24
25
namespace Luau
25
26
{
@@ -211,6 +212,15 @@ Parser::Parser(const char* buffer, size_t bufferSize, AstNameTable& names, Alloc
211
212
scratchExpr.reserve (16 );
212
213
scratchLocal.reserve (16 );
213
214
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
+ }
214
224
}
215
225
216
226
bool Parser::blockFollow (const Lexeme& l)
@@ -784,6 +794,7 @@ AstStat* Parser::parseAttributeStat()
784
794
AstExpr* expr = parsePrimaryExpr (/* asStatement= */ true );
785
795
return parseDeclaration (expr->location , attributes);
786
796
}
797
+ [[fallthrough]];
787
798
default :
788
799
return reportStatError (
789
800
lexer.current ().location ,
@@ -890,10 +901,10 @@ AstStat* Parser::parseReturn()
890
901
AstStat* Parser::parseTypeAlias (const Location& start, bool exported)
891
902
{
892
903
// parsing a type function
893
- if (FFlag::LuauUserDefinedTypeFunctions )
904
+ if (FFlag::LuauUserDefinedTypeFunctionsSyntax2 )
894
905
{
895
906
if (lexer.current ().type == Lexeme::ReservedFunction)
896
- return parseTypeFunction (start);
907
+ return parseTypeFunction (start, exported );
897
908
}
898
909
899
910
// parsing a type alias
@@ -916,20 +927,28 @@ AstStat* Parser::parseTypeAlias(const Location& start, bool exported)
916
927
}
917
928
918
929
// type function Name `(' arglist `)' `=' funcbody `end'
919
- AstStat* Parser::parseTypeFunction (const Location& start)
930
+ AstStat* Parser::parseTypeFunction (const Location& start, bool exported )
920
931
{
921
932
Lexeme matchFn = lexer.current ();
922
933
nextLexeme ();
923
934
935
+ if (exported)
936
+ report (start, " Type function cannot be exported" );
937
+
924
938
// parse the name of the type function
925
939
std::optional<Name> fnName = parseNameOpt (" type function name" );
926
940
if (!fnName)
927
941
fnName = Name (nameError, lexer.current ().location );
928
942
929
943
matchRecoveryStopOnToken[Lexeme::ReservedEnd]++;
930
944
945
+ size_t oldTypeFunctionDepth = typeFunctionDepth;
946
+ typeFunctionDepth = functionStack.size ();
947
+
931
948
AstExprFunction* body = parseFunctionBody (/* hasself */ false , matchFn, fnName->name , nullptr , AstArray<AstAttr*>({nullptr , 0 })).first ;
932
949
950
+ typeFunctionDepth = oldTypeFunctionDepth;
951
+
933
952
matchRecoveryStopOnToken[Lexeme::ReservedEnd]--;
934
953
935
954
return allocator.alloc <AstStatTypeFunction>(Location (start, body->location ), fnName->name , fnName->location , body);
@@ -2280,6 +2299,12 @@ AstExpr* Parser::parseNameExpr(const char* context)
2280
2299
{
2281
2300
AstLocal* local = *value;
2282
2301
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
+
2283
2308
return allocator.alloc <AstExprLocal>(name->location , local, local->functionDepth != functionStack.size () - 1 );
2284
2309
}
2285
2310
0 commit comments