Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 1 addition & 28 deletions lute/cli/src/tc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,6 @@
#include "Luau/FileUtils.h"
#include "Luau/Frontend.h"

static const std::string kLuteDefinitions = R"LUTE_TYPES(
-- Net api
declare net: {
get: (string) -> string,
getAsync: (string) -> string,
}
-- fs api
declare class file end
declare fs: {
-- probably not the correct sig
open: (string, "r" | "w" | "a" | "r+" | "w+") -> file,
close: (file) -> (),
read: (file) -> string,
write: (file, string) -> (),
readfiletostring : (string) -> string,
writestringtofile : (string, string) -> (),
-- is this right? I feel like we want a promise type here
readasync : (string) -> string,
}

-- globals
declare function spawn(path: string): any

)LUTE_TYPES";

struct LuteFileResolver : Luau::LuteModuleResolver
{
std::optional<Luau::SourceCode> readSource(const Luau::ModuleName& name) override
Expand Down Expand Up @@ -186,11 +161,9 @@ int typecheck(const std::vector<std::string>& sourceFilesInput, LuteReporter& re
LuteFileResolver fileResolver;
Luau::LuteConfigResolver configResolver(mode);
Luau::Frontend frontend(&fileResolver, &configResolver, frontendOptions);
frontend.setLuauSolverMode(Luau::SolverMode::New);

Luau::registerBuiltinGlobals(frontend, frontend.globals);
Luau::LoadDefinitionFileResult loadResult =
frontend.loadDefinitionFile(frontend.globals, frontend.globals.globalScope, kLuteDefinitions, "@luau", false, false);
LUAU_ASSERT(loadResult.success);
Luau::freeze(frontend.globals.globalTypes);

for (const std::string& path : sourceFiles)
Expand Down
3 changes: 2 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ target_sources(Lute.Test PRIVATE
src/packagerequire.test.cpp
src/require.test.cpp
src/staticrequires.test.cpp
src/stdsystem.test.cpp)
src/stdsystem.test.cpp
src/typecheck.test.cpp)

set_target_properties(Lute.Test PROPERTIES OUTPUT_NAME lute-tests)
target_compile_features(Lute.Test PUBLIC cxx_std_17)
Expand Down
39 changes: 39 additions & 0 deletions tests/cli/check.test.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
local fs = require("@std/fs")
local path = require("@std/path")
local process = require("@std/process")
local system = require("@std/system")
local test = require("@std/test")

local lutePath = path.format(process.execpath())
local tmpDir = system.tmpdir()

test.suite("LuteTypeCheck", function(suite)
suite:case("UsesNewSolver", function(assert)
local testFilePath = path.format(path.join(tmpDir, "check_new_solver.luau"))
-- This file should fail the old solver
fs.writestringtofile(
testFilePath,
[[
function add(a, b)
return a + b
end
local vec2 = {}
function vec2.new(x, y)
return setmetatable({ x = x or 0, y = y or 0 }, {
__add = function(v1, v2)
return { x = v1.x + v2.x, y = v1.y + v2.y }
end,
})
end
add(1, 1)
add(vec2.new(0, 0), vec2.new(1, 1))

add(vec2.new(0, 0), vec2.new(1,1))
]]
)

local result = process.run({ lutePath, "check", testFilePath })
assert.eq(result.exitcode, 0)
fs.remove(testFilePath)
end)
end)
14 changes: 14 additions & 0 deletions tests/src/staticrequires/newsolver.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- This file should fail the old solver
function add(a, b)
return a + b
end
local vec2 = {}
function vec2.new(x, y)
return setmetatable({ x = x or 0, y = y or 0 }, {
__add = function(v1, v2)
return { x = v1.x + v2.x, y = v1.y + v2.y }
end,
})
end
add(1, 1)
add(vec2.new(0, 0), vec2.new(1, 1))
16 changes: 16 additions & 0 deletions tests/src/typecheck.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "lute/tc.h"

#include "Luau/FileUtils.h"

#include "doctest.h"
#include "lutefixture.h"
#include "luteprojectroot.h"

TEST_CASE_FIXTURE(LuteFixture, "typecheck_uses_new_solver")
{
std::string luteProjectRoot = getLuteProjectRootAbsolute();
std::string testFilePath = joinPaths(luteProjectRoot, "tests/src/staticrequires/newsolver.luau");

auto result = typecheck({testFilePath}, getReporter());
CHECK(result == 0);
}