Skip to content

Commit 102c388

Browse files
Lute check uses the new solver by default (#711)
Addresses #710 Updates `lute check` to use the new solver by default. Fails the test as expected without the change ``` Failed Tests (1): ❌ lute check.uses new solver /Users/rng/dev/lute/tests/cli/check.test.luau:32 eq: 1 ~= 0 ```
1 parent a179487 commit 102c388

File tree

5 files changed

+49
-29
lines changed

5 files changed

+49
-29
lines changed

lute/cli/src/tc.cpp

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,6 @@
88
#include "Luau/FileUtils.h"
99
#include "Luau/Frontend.h"
1010

11-
static const std::string kLuteDefinitions = R"LUTE_TYPES(
12-
-- Net api
13-
declare net: {
14-
get: (string) -> string,
15-
getAsync: (string) -> string,
16-
}
17-
-- fs api
18-
declare class file end
19-
declare fs: {
20-
-- probably not the correct sig
21-
open: (string, "r" | "w" | "a" | "r+" | "w+") -> file,
22-
close: (file) -> (),
23-
read: (file) -> string,
24-
write: (file, string) -> (),
25-
readfiletostring : (string) -> string,
26-
writestringtofile : (string, string) -> (),
27-
-- is this right? I feel like we want a promise type here
28-
readasync : (string) -> string,
29-
}
30-
31-
-- globals
32-
declare function spawn(path: string): any
33-
34-
)LUTE_TYPES";
35-
3611
struct LuteFileResolver : Luau::LuteModuleResolver
3712
{
3813
std::optional<Luau::SourceCode> readSource(const Luau::ModuleName& name) override
@@ -186,11 +161,9 @@ int typecheck(const std::vector<std::string>& sourceFilesInput, LuteReporter& re
186161
LuteFileResolver fileResolver;
187162
Luau::LuteConfigResolver configResolver(mode);
188163
Luau::Frontend frontend(&fileResolver, &configResolver, frontendOptions);
164+
frontend.setLuauSolverMode(Luau::SolverMode::New);
189165

190166
Luau::registerBuiltinGlobals(frontend, frontend.globals);
191-
Luau::LoadDefinitionFileResult loadResult =
192-
frontend.loadDefinitionFile(frontend.globals, frontend.globals.globalScope, kLuteDefinitions, "@luau", false, false);
193-
LUAU_ASSERT(loadResult.success);
194167
Luau::freeze(frontend.globals.globalTypes);
195168

196169
for (const std::string& path : sourceFiles)

tests/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ target_sources(Lute.Test PRIVATE
2424
src/packagerequire.test.cpp
2525
src/require.test.cpp
2626
src/staticrequires.test.cpp
27-
src/stdsystem.test.cpp)
27+
src/stdsystem.test.cpp
28+
src/typecheck.test.cpp)
2829

2930
set_target_properties(Lute.Test PROPERTIES OUTPUT_NAME lute-tests)
3031
target_compile_features(Lute.Test PUBLIC cxx_std_17)

tests/cli/check.test.luau

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
local fs = require("@std/fs")
2+
local path = require("@std/path")
3+
local process = require("@std/process")
4+
local system = require("@std/system")
5+
local test = require("@std/test")
6+
7+
local lutePath = path.format(process.execpath())
8+
9+
test.suite("LuteTypeCheck", function(suite)
10+
suite:case("UsesNewSolver", function(assert)
11+
local testFilePath = path.format(path.join("tests", "src", "staticrequires", "newsolver.luau"))
12+
13+
local result = process.run({ lutePath, "check", testFilePath })
14+
assert.eq(result.exitcode, 0)
15+
end)
16+
end)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- This file should fail the old solver
2+
function add(a, b)
3+
return a + b
4+
end
5+
local vec2 = {}
6+
function vec2.new(x, y)
7+
return setmetatable({ x = x or 0, y = y or 0 }, {
8+
__add = function(v1, v2)
9+
return { x = v1.x + v2.x, y = v1.y + v2.y }
10+
end,
11+
})
12+
end
13+
add(1, 1)
14+
add(vec2.new(0, 0), vec2.new(1, 1))

tests/src/typecheck.test.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "lute/tc.h"
2+
3+
#include "Luau/FileUtils.h"
4+
5+
#include "doctest.h"
6+
#include "lutefixture.h"
7+
#include "luteprojectroot.h"
8+
9+
TEST_CASE_FIXTURE(LuteFixture, "typecheck_uses_new_solver")
10+
{
11+
std::string luteProjectRoot = getLuteProjectRootAbsolute();
12+
std::string testFilePath = joinPaths(luteProjectRoot, "tests/src/staticrequires/newsolver.luau");
13+
14+
auto result = typecheck({testFilePath}, getReporter());
15+
CHECK(result == 0);
16+
}

0 commit comments

Comments
 (0)