mirror of
https://github.com/luau-lang/luau.git
synced 2025-01-09 04:49:10 +00:00
Fix negation type 'inner' method in user-defined type functions (#1582)
Some checks failed
benchmark / callgrind (map[branch:main name:luau-lang/benchmark-data], ubuntu-22.04) (push) Has been cancelled
build / macos (push) Has been cancelled
build / macos-arm (push) Has been cancelled
build / ubuntu (push) Has been cancelled
build / windows (Win32) (push) Has been cancelled
build / windows (x64) (push) Has been cancelled
build / coverage (push) Has been cancelled
build / web (push) Has been cancelled
release / macos (push) Has been cancelled
release / ubuntu (push) Has been cancelled
release / windows (push) Has been cancelled
release / web (push) Has been cancelled
Some checks failed
benchmark / callgrind (map[branch:main name:luau-lang/benchmark-data], ubuntu-22.04) (push) Has been cancelled
build / macos (push) Has been cancelled
build / macos-arm (push) Has been cancelled
build / ubuntu (push) Has been cancelled
build / windows (Win32) (push) Has been cancelled
build / windows (x64) (push) Has been cancelled
build / coverage (push) Has been cancelled
build / web (push) Has been cancelled
release / macos (push) Has been cancelled
release / ubuntu (push) Has been cancelled
release / windows (push) Has been cancelled
release / web (push) Has been cancelled
Fixes #1580
This commit is contained in:
parent
8f94786ceb
commit
9a102e2aff
2 changed files with 38 additions and 3 deletions
|
@ -14,6 +14,7 @@
|
|||
#include <vector>
|
||||
|
||||
LUAU_DYNAMIC_FASTINT(LuauTypeFunctionSerdeIterationLimit)
|
||||
LUAU_FASTFLAGVARIABLE(LuauUserTypeFunFixInner)
|
||||
LUAU_FASTFLAGVARIABLE(LuauUserTypeFunPrintToError)
|
||||
LUAU_FASTFLAGVARIABLE(LuauUserTypeFunFixNoReadWrite)
|
||||
LUAU_FASTFLAGVARIABLE(LuauUserTypeFunThreadBuffer)
|
||||
|
@ -413,10 +414,21 @@ static int getNegatedValue(lua_State* L)
|
|||
luaL_error(L, "type.inner: expected 1 argument, but got %d", argumentCount);
|
||||
|
||||
TypeFunctionTypeId self = getTypeUserData(L, 1);
|
||||
if (auto tfnt = get<TypeFunctionNegationType>(self); !tfnt)
|
||||
allocTypeUserData(L, tfnt->type->type);
|
||||
|
||||
if (FFlag::LuauUserTypeFunFixInner)
|
||||
{
|
||||
if (auto tfnt = get<TypeFunctionNegationType>(self); tfnt)
|
||||
allocTypeUserData(L, tfnt->type->type);
|
||||
else
|
||||
luaL_error(L, "type.inner: cannot call inner method on non-negation type: `%s` type", getTag(L, self).c_str());
|
||||
}
|
||||
else
|
||||
luaL_error(L, "type.inner: cannot call inner method on non-negation type: `%s` type", getTag(L, self).c_str());
|
||||
{
|
||||
if (auto tfnt = get<TypeFunctionNegationType>(self); !tfnt)
|
||||
allocTypeUserData(L, tfnt->type->type);
|
||||
else
|
||||
luaL_error(L, "type.inner: cannot call inner method on non-negation type: `%s` type", getTag(L, self).c_str());
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ using namespace Luau;
|
|||
|
||||
LUAU_FASTFLAG(LuauSolverV2)
|
||||
LUAU_FASTFLAG(LuauUserTypeFunFixNoReadWrite)
|
||||
LUAU_FASTFLAG(LuauUserTypeFunFixInner)
|
||||
LUAU_FASTFLAG(LuauUserTypeFunPrintToError)
|
||||
LUAU_FASTFLAG(LuauUserTypeFunExportedAndLocal)
|
||||
LUAU_FASTFLAG(LuauUserDefinedTypeFunParseExport)
|
||||
|
@ -475,6 +476,28 @@ TEST_CASE_FIXTURE(BuiltinsFixture, "udtf_negation_methods_work")
|
|||
CHECK(toString(tpm->givenTp) == "~string");
|
||||
}
|
||||
|
||||
TEST_CASE_FIXTURE(ClassFixture, "udtf_negation_inner")
|
||||
{
|
||||
ScopedFastFlag newSolver{FFlag::LuauSolverV2, true};
|
||||
ScopedFastFlag luauUserTypeFunFixInner{FFlag::LuauUserTypeFunFixInner, true};
|
||||
|
||||
CheckResult result = check(R"(
|
||||
type function pass(t)
|
||||
return types.negationof(t):inner()
|
||||
end
|
||||
|
||||
type function fail(t)
|
||||
return t:inner()
|
||||
end
|
||||
|
||||
local function ok(idx: pass<number>): number return idx end
|
||||
local function notok(idx: fail<number>): never return idx end
|
||||
)");
|
||||
|
||||
LUAU_REQUIRE_ERROR_COUNT(4, result);
|
||||
CHECK(toString(result.errors[0]) == R"('fail' type function errored at runtime: [string "fail"]:7: type.inner: cannot call inner method on non-negation type: `number` type)");
|
||||
}
|
||||
|
||||
TEST_CASE_FIXTURE(BuiltinsFixture, "udtf_table_serialization_works")
|
||||
{
|
||||
ScopedFastFlag newSolver{FFlag::LuauSolverV2, true};
|
||||
|
|
Loading…
Reference in a new issue