From e8e84a72c5f66a43945bf90743e69142e36ec366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petri=20H=C3=A4kkinen?= Date: Mon, 16 Dec 2024 15:06:53 +0200 Subject: [PATCH] Modify 3rd argument of vector.create to be optional in type definitions --- Analysis/src/EmbeddedBuiltinDefinitions.cpp | 17 +++++++++++++++-- tests/Conformance.test.cpp | 1 + tests/Fixture.cpp | 3 +++ tests/NonStrictTypeChecker.test.cpp | 4 +++- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Analysis/src/EmbeddedBuiltinDefinitions.cpp b/Analysis/src/EmbeddedBuiltinDefinitions.cpp index 828fc7ed3..e4b561d41 100644 --- a/Analysis/src/EmbeddedBuiltinDefinitions.cpp +++ b/Analysis/src/EmbeddedBuiltinDefinitions.cpp @@ -2,6 +2,7 @@ #include "Luau/BuiltinDefinitions.h" LUAU_FASTFLAG(LuauMathMap) +LUAU_FASTFLAG(LuauVector2Constructor) LUAU_FASTFLAGVARIABLE(LuauVectorDefinitions) LUAU_FASTFLAGVARIABLE(LuauVectorDefinitionsExtra) @@ -513,10 +514,22 @@ std::string getBuiltinDefinitionSource() { std::string result = FFlag::LuauMathMap ? kBuiltinDefinitionLuaSrcChecked : kBuiltinDefinitionLuaSrcChecked_DEPRECATED; + std::string vectorSrc; if (FFlag::LuauVectorDefinitionsExtra) - result += kBuiltinDefinitionVectorSrc; + vectorSrc = kBuiltinDefinitionVectorSrc; else if (FFlag::LuauVectorDefinitions) - result += kBuiltinDefinitionVectorSrc_DEPRECATED; + vectorSrc = kBuiltinDefinitionVectorSrc_DEPRECATED; + + if (FFlag::LuauVector2Constructor && !vectorSrc.empty()) + { + std::string what = "create: @checked (x: number, y: number, z: number) -> vector"; + std::string replacement = "create: @checked (x: number, y: number, z: number?) -> vector"; + std::string::size_type pos = vectorSrc.find(what); + LUAU_ASSERT(pos != std::string::npos); + vectorSrc.replace(pos, what.size(), replacement); + } + + result += vectorSrc; return result; } diff --git a/tests/Conformance.test.cpp b/tests/Conformance.test.cpp index 59201d268..56ddb9135 100644 --- a/tests/Conformance.test.cpp +++ b/tests/Conformance.test.cpp @@ -990,6 +990,7 @@ static void populateRTTI(lua_State* L, Luau::TypeId type) TEST_CASE("Types") { ScopedFastFlag luauVectorDefinitions{FFlag::LuauVectorDefinitions, true}; + ScopedFastFlag luauVector2Constructor{FFlag::LuauVector2Constructor, true}; runConformance( "types.lua", diff --git a/tests/Fixture.cpp b/tests/Fixture.cpp index 5a2f9319f..e22e52b00 100644 --- a/tests/Fixture.cpp +++ b/tests/Fixture.cpp @@ -25,6 +25,7 @@ static const char* mainModuleName = "MainModule"; LUAU_FASTFLAG(LuauSolverV2); +LUAU_FASTFLAG(LuauVector2Constructor) LUAU_FASTFLAG(DebugLuauLogSolverToJsonFile) LUAU_FASTFLAGVARIABLE(DebugLuauForceAllNewSolverTests); @@ -580,6 +581,8 @@ LoadDefinitionFileResult Fixture::loadDefinition(const std::string& source, bool BuiltinsFixture::BuiltinsFixture(bool prepareAutocomplete) : Fixture(prepareAutocomplete) { + ScopedFastFlag luauVector2Constructor{FFlag::LuauVector2Constructor, true}; + Luau::unfreeze(frontend.globals.globalTypes); Luau::unfreeze(frontend.globalsForAutocomplete.globalTypes); diff --git a/tests/NonStrictTypeChecker.test.cpp b/tests/NonStrictTypeChecker.test.cpp index 8d13ebde9..f613e7502 100644 --- a/tests/NonStrictTypeChecker.test.cpp +++ b/tests/NonStrictTypeChecker.test.cpp @@ -15,6 +15,7 @@ #include LUAU_FASTFLAG(LuauCountSelfCallsNonstrict) +LUAU_FASTFLAG(LuauVector2Constructor) using namespace Luau; @@ -581,7 +582,8 @@ buffer.readi8(b, 0) TEST_CASE_FIXTURE(NonStrictTypeCheckerFixture, "nonstrict_method_calls") { - ScopedFastFlag sff{FFlag::LuauCountSelfCallsNonstrict, true}; + ScopedFastFlag luauCountSelfCallsNonstrict{FFlag::LuauCountSelfCallsNonstrict, true}; + ScopedFastFlag luauVector2Constructor{FFlag::LuauVector2Constructor, true}; Luau::unfreeze(frontend.globals.globalTypes); Luau::unfreeze(frontend.globalsForAutocomplete.globalTypes);