Bind data imports properly when already resolved

This commit is contained in:
Muh Muhten authored and Nico Williams committed 2019-02-20 20:02:41 -06:00
1 parent e843a4fdf9
commit 1ef90acb38
2 files changed
+18 -2

No files matched your search

+14 -2
View File
@@ -275,11 +275,23 @@ static int process_dependencies(jq_state *jq, jv jq_origin, jv lib_origin, block
jv_free(lib_origin); jv_free(lib_origin);
return 1; return 1;
} }
if (is_data) {
// Can't reuse data libs because the wrong name is bound
block dep_def_block;
nerrors += load_library(jq, resolved, is_data, raw, as_str, &dep_def_block, lib_state);
if (nerrors == 0) {
// Bind as both $data::data and $data for backward compatibility vs common sense
bk = block_bind_library(dep_def_block, bk, OP_IS_CALL_PSEUDO, as_str);
bk = block_bind_library(dep_def_block, bk, OP_IS_CALL_PSEUDO, NULL);
}
} else {
uint64_t state_idx = 0; uint64_t state_idx = 0;
for (; state_idx < lib_state->ct; ++state_idx) { for (; state_idx < lib_state->ct; ++state_idx) {
if (strcmp(lib_state->names[state_idx],jv_string_value(resolved)) == 0) if (strcmp(lib_state->names[state_idx],jv_string_value(resolved)) == 0)
break; break;
} }
if (state_idx < lib_state->ct) { // Found if (state_idx < lib_state->ct) { // Found
jv_free(resolved); jv_free(resolved);
// Bind the library to the program // Bind the library to the program
@@ -291,10 +303,10 @@ static int process_dependencies(jq_state *jq, jv jq_origin, jv lib_origin, block
if (nerrors == 0) { if (nerrors == 0) {
// Bind the library to the program // Bind the library to the program
bk = block_bind_library(dep_def_block, bk, OP_IS_CALL_PSEUDO, as_str); bk = block_bind_library(dep_def_block, bk, OP_IS_CALL_PSEUDO, as_str);
if (is_data)
bk = block_bind_library(dep_def_block, bk, OP_IS_CALL_PSEUDO, NULL);
} }
} }
}
jv_free(as); jv_free(as);
} }
jv_free(lib_origin); jv_free(lib_origin);
+4
View File
@@ -1392,6 +1392,10 @@ include "c"; [a, c]
null null
[0,"acmehbah"] [0,"acmehbah"]
import "data" as $e; import "data" as $d; [$d[].this,$e[].that,$d::d[].this,$e::e[].that]|join(";")
null
"is a test;is too;is a test;is too"
%%FAIL %%FAIL
module (.+1); 0 module (.+1); 0
jq: error: Module metadata must be constant at <top-level>, line 1: jq: error: Module metadata must be constant at <top-level>, line 1: