mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Add test case
This commit is contained in:
parent
95d9c6d194
commit
9f025a0d5f
1 changed files with 18 additions and 0 deletions
|
@ -91,6 +91,13 @@ struct ClassFixture : BuiltinsFixture
|
||||||
typeChecker.globalScope->exportedTypeBindings["Vector2"] = TypeFun{{}, vector2InstanceType};
|
typeChecker.globalScope->exportedTypeBindings["Vector2"] = TypeFun{{}, vector2InstanceType};
|
||||||
addGlobalBinding(frontend, "Vector2", vector2Type, "@test");
|
addGlobalBinding(frontend, "Vector2", vector2Type, "@test");
|
||||||
|
|
||||||
|
TypeId callableClassMetaType = arena.addType(TableTypeVar{});
|
||||||
|
TypeId callableClassType = arena.addType(ClassTypeVar{"CallableClass", {}, nullopt, callableClassMetaType, {}, {}, "Test"});
|
||||||
|
getMutable<TableTypeVar>(callableClassMetaType)->props = {
|
||||||
|
{"__call", {makeFunction(arena, nullopt, {callableClassType, typeChecker.stringType}, {typeChecker.numberType})}},
|
||||||
|
};
|
||||||
|
typeChecker.globalScope->exportedTypeBindings["CallableClass"] = TypeFun{{}, callableClassType};
|
||||||
|
|
||||||
for (const auto& [name, tf] : typeChecker.globalScope->exportedTypeBindings)
|
for (const auto& [name, tf] : typeChecker.globalScope->exportedTypeBindings)
|
||||||
persist(tf.type);
|
persist(tf.type);
|
||||||
|
|
||||||
|
@ -514,4 +521,15 @@ TEST_CASE_FIXTURE(ClassFixture, "unions_of_intersections_of_classes")
|
||||||
LUAU_REQUIRE_NO_ERRORS(result);
|
LUAU_REQUIRE_NO_ERRORS(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE_FIXTURE(ClassFixture, "callable_classes")
|
||||||
|
{
|
||||||
|
CheckResult result = check(R"(
|
||||||
|
local x : CallableClass
|
||||||
|
local y = x("testing")
|
||||||
|
)");
|
||||||
|
|
||||||
|
LUAU_REQUIRE_NO_ERRORS(result);
|
||||||
|
CHECK_EQ("number", toString(requireType("y")));
|
||||||
|
}
|
||||||
|
|
||||||
TEST_SUITE_END();
|
TEST_SUITE_END();
|
||||||
|
|
Loading…
Add table
Reference in a new issue