diff --git a/src/Idris/ModTree.idr b/src/Idris/ModTree.idr index 18c6b4e..f249eb9 100644 --- a/src/Idris/ModTree.idr +++ b/src/Idris/ModTree.idr @@ -85,14 +85,17 @@ mkModTree loc done mod Nothing => do (file, modInfo) <- readHeader loc mod let imps = map path (imports modInfo) - ms <- traverse (mkModTree loc done) imps + ms <- traverse (mkModTree loc (mod :: done)) imps let mt = MkModTree mod (Just file) ms all <- get AllMods put AllMods ((mod, mt) :: all) pure mt Just m => pure m) -- Couldn't find source, assume it's in a package directory - (\err => pure (MkModTree mod Nothing [])) + (\err => + case err of + CyclicImports _ => throw err + _ => pure (MkModTree mod Nothing [])) -- Given a module tree, returns the modules in the reverse order they need to -- be built, including their dependencies @@ -112,7 +115,6 @@ mkBuildMods acc mod -- Given a main file name, return the list of modules that need to be -- built for that main file, in the order they need to be built -export getBuildMods : {auto c : Ref Ctxt Defs} -> {auto o : Ref ROpts REPLOpts} -> FC -> (mainFile : String) -> diff --git a/tests/Main.idr b/tests/Main.idr index 862ce54..3237d03 100644 --- a/tests/Main.idr +++ b/tests/Main.idr @@ -32,7 +32,7 @@ idrisTests "coverage001", "coverage002", "coverage003", "coverage004", "error001", "error002", "error003", "error004", "error005", "error006", "error007", "error008", "error009", "error010", - "import001", "import002", "import003", + "import001", "import002", "import003", "import004", "interactive001", "interactive002", "interactive003", "interactive004", "interactive005", "interactive006", "interactive007", "interactive008", "interactive009", "interactive010", "interactive011", "interactive012", diff --git a/tests/idris2/import004/Cycle1.idr b/tests/idris2/import004/Cycle1.idr new file mode 100644 index 0000000..5ff245f --- /dev/null +++ b/tests/idris2/import004/Cycle1.idr @@ -0,0 +1,3 @@ +module Cycle1 + +import Cycle2 diff --git a/tests/idris2/import004/Cycle2.idr b/tests/idris2/import004/Cycle2.idr new file mode 100644 index 0000000..4de786c --- /dev/null +++ b/tests/idris2/import004/Cycle2.idr @@ -0,0 +1,3 @@ +module Cycle2 + +import Cycle1 diff --git a/tests/idris2/import004/Loop.idr b/tests/idris2/import004/Loop.idr new file mode 100644 index 0000000..c9d26cc --- /dev/null +++ b/tests/idris2/import004/Loop.idr @@ -0,0 +1,3 @@ +module Loop + +import Loop diff --git a/tests/idris2/import004/expected b/tests/idris2/import004/expected new file mode 100644 index 0000000..cb81d7f --- /dev/null +++ b/tests/idris2/import004/expected @@ -0,0 +1,2 @@ +Uncaught error: Module imports form a cycle: Cycle2 -> Cycle1 -> Cycle1 +Uncaught error: Module imports form a cycle: Loop -> Loop diff --git a/tests/idris2/import004/run b/tests/idris2/import004/run new file mode 100755 index 0000000..e2540fc --- /dev/null +++ b/tests/idris2/import004/run @@ -0,0 +1,4 @@ +$1 Cycle1.idr +$1 Loop.idr + +rm -rf build