Skip to content

Commit 018460d

Browse files
committed
fix forward declaration of some types not getting reset
1 parent 3677dee commit 018460d

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

nattlua/base_environment.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,23 @@ return {
114114

115115
assert(compiler:Analyze(analyzer))
116116

117+
do
118+
local globals = {
119+
"require",
120+
"getmetatable",
121+
"setmetatable",
122+
"rawget",
123+
"type",
124+
}
125+
126+
for i = 1, #globals do
127+
local key = LStringNoMeta(globals[i])
128+
local val = typesystem_env:Get(key)
129+
130+
if val then runtime_env:Set(key, val) end
131+
end
132+
end
133+
117134
if parent_analyzer then
118135
for path, _ in pairs(compiler.analyzer.parsed_paths) do
119136
parent_analyzer.parsed_paths[path] = true

test/tests/language_server/editor_helper.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
_G.TEST = true
22
local EditorHelper = require("language_server.editor_helper")
3+
local LStringNoMeta = require("nattlua.types.string").LStringNoMeta
34
local path = "./test.nlua"
45

56
local function single_file(code)
@@ -29,6 +30,17 @@ do
2930
assert(editor:GetHover(path, 0, 13).obj:GetData() == 2)
3031
end
3132

33+
do
34+
local helper = EditorHelper.New()
35+
local runtime_env, typesystem_env = helper:GetEnvironment()
36+
37+
for _, env in ipairs({runtime_env, typesystem_env}) do
38+
assert(env:Get(LStringNoMeta("type")).Type == "function")
39+
assert(env:Get(LStringNoMeta("require")).Type == "function")
40+
assert(env:Get(LStringNoMeta("rawget")).Type == "function")
41+
end
42+
end
43+
3244
do
3345
local code = [[
3446
local a: number = 1

0 commit comments

Comments
 (0)