Skip to content

Commit

Permalink
Modify 3rd argument of vector.create to be optional in type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
petrihakkinen committed Dec 16, 2024
1 parent 044c97b commit e8e84a7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
17 changes: 15 additions & 2 deletions Analysis/src/EmbeddedBuiltinDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "Luau/BuiltinDefinitions.h"

LUAU_FASTFLAG(LuauMathMap)
LUAU_FASTFLAG(LuauVector2Constructor)

LUAU_FASTFLAGVARIABLE(LuauVectorDefinitions)
LUAU_FASTFLAGVARIABLE(LuauVectorDefinitionsExtra)
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions tests/Conformance.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions tests/Fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
static const char* mainModuleName = "MainModule";

LUAU_FASTFLAG(LuauSolverV2);
LUAU_FASTFLAG(LuauVector2Constructor)
LUAU_FASTFLAG(DebugLuauLogSolverToJsonFile)

LUAU_FASTFLAGVARIABLE(DebugLuauForceAllNewSolverTests);
Expand Down Expand Up @@ -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);

Expand Down
4 changes: 3 additions & 1 deletion tests/NonStrictTypeChecker.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <iostream>

LUAU_FASTFLAG(LuauCountSelfCallsNonstrict)
LUAU_FASTFLAG(LuauVector2Constructor)

using namespace Luau;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e8e84a7

Please sign in to comment.