Catch cyclic imports harder. Add 2 tests to confirm.
This commit is contained in:
parent
fdaa723c4a
commit
ab3921f27e
3 changed files with 34 additions and 11 deletions
|
@ -1545,10 +1545,18 @@ let rec project_ident_from_items
|
||||||
(cx:ctxt)
|
(cx:ctxt)
|
||||||
(lchk:loop_check)
|
(lchk:loop_check)
|
||||||
(scopes:scope list)
|
(scopes:scope list)
|
||||||
|
(scope_id:node_id)
|
||||||
((view:Ast.mod_view),(items:Ast.mod_items))
|
((view:Ast.mod_view),(items:Ast.mod_items))
|
||||||
(ident:Ast.ident)
|
(ident:Ast.ident)
|
||||||
(inside:bool)
|
(inside:bool)
|
||||||
: resolved =
|
: resolved =
|
||||||
|
|
||||||
|
let lchk =
|
||||||
|
if List.mem (scope_id, ident) lchk
|
||||||
|
then err (Some scope_id) "cyclic import for ident %s" ident
|
||||||
|
else (scope_id, ident)::lchk
|
||||||
|
in
|
||||||
|
|
||||||
if not (inside || (exports_permit view ident))
|
if not (inside || (exports_permit view ident))
|
||||||
then None
|
then None
|
||||||
else
|
else
|
||||||
|
@ -1558,7 +1566,8 @@ let rec project_ident_from_items
|
||||||
| None ->
|
| None ->
|
||||||
match htab_search view.Ast.view_imports ident with
|
match htab_search view.Ast.view_imports ident with
|
||||||
None -> None
|
None -> None
|
||||||
| Some name -> lookup_by_name cx lchk scopes name
|
| Some name ->
|
||||||
|
lookup_by_name cx lchk scopes name
|
||||||
|
|
||||||
and found cx scopes id =
|
and found cx scopes id =
|
||||||
Hashtbl.replace cx.ctxt_node_referenced id ();
|
Hashtbl.replace cx.ctxt_node_referenced id ();
|
||||||
|
@ -1578,7 +1587,7 @@ and project_name_comp_from_resolved
|
||||||
let ident = get_name_comp_ident ext in
|
let ident = get_name_comp_ident ext in
|
||||||
let md = get_mod_item cx id in
|
let md = get_mod_item cx id in
|
||||||
Hashtbl.replace cx.ctxt_node_referenced id ();
|
Hashtbl.replace cx.ctxt_node_referenced id ();
|
||||||
project_ident_from_items cx lchk scopes md ident false
|
project_ident_from_items cx lchk scopes id md ident false
|
||||||
|
|
||||||
and lookup_by_name
|
and lookup_by_name
|
||||||
(cx:ctxt)
|
(cx:ctxt)
|
||||||
|
@ -1602,12 +1611,6 @@ and lookup_by_ident
|
||||||
(ident:Ast.ident)
|
(ident:Ast.ident)
|
||||||
: resolved =
|
: resolved =
|
||||||
|
|
||||||
let passing id =
|
|
||||||
if List.mem (id, ident) lchk
|
|
||||||
then err (Some id) "cyclic import for ident %s" ident
|
|
||||||
else (id, ident)::lchk
|
|
||||||
in
|
|
||||||
|
|
||||||
let check_slots scopes islots =
|
let check_slots scopes islots =
|
||||||
arr_search islots
|
arr_search islots
|
||||||
(fun _ (sloti,ident') ->
|
(fun _ (sloti,ident') ->
|
||||||
|
@ -1651,7 +1654,7 @@ and lookup_by_ident
|
||||||
|
|
||||||
| SCOPE_crate crate ->
|
| SCOPE_crate crate ->
|
||||||
project_ident_from_items
|
project_ident_from_items
|
||||||
cx (passing crate.id) scopes crate.node.Ast.crate_items ident true
|
cx lchk scopes crate.id crate.node.Ast.crate_items ident true
|
||||||
|
|
||||||
| SCOPE_obj_fn fn ->
|
| SCOPE_obj_fn fn ->
|
||||||
would_capture (check_slots scopes fn.node.Ast.fn_input_slots)
|
would_capture (check_slots scopes fn.node.Ast.fn_input_slots)
|
||||||
|
@ -1671,8 +1674,8 @@ and lookup_by_ident
|
||||||
end
|
end
|
||||||
|
|
||||||
| Ast.MOD_ITEM_mod md ->
|
| Ast.MOD_ITEM_mod md ->
|
||||||
project_ident_from_items cx (passing item.id)
|
project_ident_from_items cx lchk
|
||||||
scopes md ident true
|
scopes item.id md ident true
|
||||||
|
|
||||||
| _ -> None
|
| _ -> None
|
||||||
in
|
in
|
||||||
|
|
13
src/test/compile-fail/import-loop-2.rs
Normal file
13
src/test/compile-fail/import-loop-2.rs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
// error-pattern:cyclic import
|
||||||
|
|
||||||
|
mod a {
|
||||||
|
import b.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
mod b {
|
||||||
|
import a.x;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
auto y = x;
|
||||||
|
}
|
||||||
|
}
|
7
src/test/compile-fail/import-loop.rs
Normal file
7
src/test/compile-fail/import-loop.rs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
// error-pattern:cyclic import
|
||||||
|
|
||||||
|
import x;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
auto y = x;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue