Commit 48550efa authored by Jamie A. Jennings's avatar Jamie A. Jennings

Fixed #105 exception when --rpl on command line includes a package declaration

parent 951213ad
Pipeline #71510981 passed with stage
in 1 minute and 10 seconds
......@@ -876,18 +876,8 @@ function ast.dependencies_of(a)
ast.cooked.is(a) or
ast.raw.is(a)) then
return ast.dependencies_of(a.exp)
elseif (ast.literal.is(a) or
ast.hashtag.is(a) or
ast.string.is(a) or
ast.int.is(a) or
ast.cs_named.is(a) or
ast.cs_list.is(a) or
ast.cs_range.is(a) or
ast.cs_intersection.is(a) or
ast.cs_difference.is(a)) then
return {}
else
assert(false, "ast.dependencies_of received an unexpected ast type: " .. tostring(a))
return {}
end
end
......
......@@ -40,8 +40,27 @@ function p.load_file(en, filename)
return ok, messages
end
local function declares_package(a)
if ast.block.is(a) then
for _, s in ipairs(a.stmts) do
if ast.pdecl.is(s) then
return true
end
end -- for
end
return false
end
-- FUTURE: Change this to use en:block_dependencies(...)
local function import_dependencies(en, a, msgs)
-- Kind of an arbitrary decision here, but we will not automatically import
-- dependencies if we are given an rpl string that defines a package, e.g.
-- bin/rosie --rpl 'package foo x="a" num.any' match 'foo.x' <<<"a 123"
-- This command (above) will fail because the foo package should explicitly
-- import the num package.
if declares_package(a) then
return false
end
local deps = en.compiler.dependencies_of(a)
local all_ok = true
for _, packagename in ipairs(deps) do
......
......@@ -749,8 +749,18 @@ end
results_txt = table.concat(results, '\n')
check_lua_error(results_txt)
cmd = rosie_cmd .. ' --norcfile --rpl \'package foo x="a" num.any\' ' ..
'match "foo.x" <<<"a 123" 2>&1'
results, status, code = util.os_execute_capture(cmd, nil)
print(); print(results, #results, status, code); print()
check(#results>0, "command should have produced output")
if not check(code ~= 0, "exit status differs from expected") then
print("Command was:", cmd)
else
results_txt = table.concat(results, '\n')
check_lua_error(results_txt)
check(results_txt:find('undefined identifier: num.any', 1, true))
check(results_txt:find('undefined identifier: foo.x', 1, true))
end
return test.finish()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment