Skip to content

Commit

Permalink
give only a warning if requiring a file for using/import does not yie…
Browse files Browse the repository at this point in the history
…ld a module

fixes #4492

for #4600, don't do any requires for relative imports. we might add
some behavior here in the future, but for now looking for files in
global locations for relative module paths is clearly wrong.
  • Loading branch information
JeffBezanson committed Oct 26, 2013
1 parent c2cc3a4 commit 1e04a5e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/toplevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,12 @@ static jl_module_t *eval_import_path_(jl_array_t *args, int retrying)
if (mb->owner == m || mb->imported) {
m = (jl_module_t*)mb->value;
if (m == NULL || !jl_is_module(m))
jl_errorf("invalid module path");
jl_errorf("invalid module path (%s does not name a module)", var->name);
break;
}
}
if (m == jl_main_module) {
if (!retrying) {
if (!retrying && i==1) { // (i==1) => no require() for relative imports
if (require_func == NULL && jl_base_module != NULL)
require_func = jl_get_global(jl_base_module, jl_symbol("require"));
if (require_func != NULL) {
Expand All @@ -250,7 +250,13 @@ static jl_module_t *eval_import_path_(jl_array_t *args, int retrying)
}
}
}
jl_errorf("in module path: %s not defined", var->name);
if (retrying && require_func) {
JL_PRINTF(JL_STDERR, "Warning: requiring \"%s\" did not define a corresponding module.\n", var->name);
return NULL;
}
else {
jl_errorf("in module path: %s not defined", var->name);
}
}

for(; i < jl_array_len(args)-1; i++) {
Expand Down Expand Up @@ -301,6 +307,7 @@ jl_value_t *jl_toplevel_eval_flex(jl_value_t *e, int fast)
// handle import, using, importall, export toplevel-only forms
if (ex->head == importall_sym) {
jl_module_t *m = eval_import_path(ex->args);
if (m==NULL) return jl_nothing;
jl_sym_t *name = (jl_sym_t*)jl_cellref(ex->args, jl_array_len(ex->args)-1);
assert(jl_is_symbol(name));
m = (jl_module_t*)jl_eval_global_var(m, name);
Expand All @@ -312,6 +319,7 @@ jl_value_t *jl_toplevel_eval_flex(jl_value_t *e, int fast)

if (ex->head == using_sym) {
jl_module_t *m = eval_import_path(ex->args);
if (m==NULL) return jl_nothing;
jl_sym_t *name = (jl_sym_t*)jl_cellref(ex->args, jl_array_len(ex->args)-1);
assert(jl_is_symbol(name));
jl_module_t *u = (jl_module_t*)jl_eval_global_var(m, name);
Expand All @@ -326,6 +334,7 @@ jl_value_t *jl_toplevel_eval_flex(jl_value_t *e, int fast)

if (ex->head == import_sym) {
jl_module_t *m = eval_import_path(ex->args);
if (m==NULL) return jl_nothing;
jl_sym_t *name = (jl_sym_t*)jl_cellref(ex->args, jl_array_len(ex->args)-1);
assert(jl_is_symbol(name));
jl_module_import(jl_current_module, m, name);
Expand Down

0 comments on commit 1e04a5e

Please sign in to comment.