A peer-to-peer stack for code collaboration
Make import fail for undefined symbols (fixes #631) (#644)
Leonhard Markert6151eb2e6f5c
diff --git a/bin/rad-project b/bin/rad-projectindex 4682fc2..d8130f3 100755--- a/bin/rad-project+++ b/bin/rad-project@@ -13,7 +13,7 @@(import prelude/cmd-parsing :unqualified)(import prelude/io :as 'io)(import prelude/io-utils- '[set-git-config get-git-config process-git-with-exit!]+ '[set-git-config! get-git-config! process-git-with-exit!]:unqualified)(import monadic/issue '[create-issue-machine!] :unqualified)diff --git a/src/Radicle/Internal/PrimFns.hs b/src/Radicle/Internal/PrimFns.hsindex 5aff7ab..c70c4ec 100644--- a/src/Radicle/Internal/PrimFns.hs+++ b/src/Radicle/Internal/PrimFns.hs@@ -709,8 +709,14 @@ purePrimFns = fromList $ allDocs $let allMod = fromEnv etoImport <- case v_ ofJust vs -> do- is <- Protolude.toList <$> traverse isAtom vs ?? toLangError (OtherError "import: must be given a vector of symbols to import")- pure $ Map.restrictKeys allMod (Set.fromList is)+ is <- (Set.fromList . Protolude.toList <$> traverse isAtom vs) ?? toLangError (OtherError "import: must be given a vector of symbols to import")+ let missing = is Set.\\ Map.keysSet allMod+ if Set.null missing+ then pure $ Map.restrictKeys allMod is+ else throwErrorHere+ $ OtherError+ $ "import: cannot import undefined symbols: "+ <> T.intercalate ", " (fromIdent <$> Set.toAscList missing)Nothing -> pure allModlet qualifier = case qual ofQualified q -> ((q <> Ident "/") <>)diff --git a/test/spec/Radicle/Tests.hs b/test/spec/Radicle/Tests.hsindex 760f557..17cbfec 100644--- a/test/spec/Radicle/Tests.hs+++ b/test/spec/Radicle/Tests.hs@@ -544,6 +544,7 @@ test_eval =(import foo :unqualified)(list foo/z bar/z baz/z z)|]prog `succeedsWith` List (replicate 4 (Number 3))+, testCase "Modules don't leak non-exported defs" $ dolet prog = [s|(module{:module 'foo :doc "" :exports '[z]}@@ -557,6 +558,17 @@ test_eval =, testCase "Modules complain if exports are undefined" $ dolet prog = [s|(module {:module 'foo :doc "" :exports '[x y]} (def x 0))|]prog `failsWith` ModuleError (UndefinedExports [ident|foo|] [[ident|y|]])++ , testCase "Importing complains if symbols are not exported" $ do+ let prog = [s|(module+ {:module 'foo :doc "" :exports '[x]}+ (def x 1) ;; x: defined and exported+ (def y 2) ;; y: defined but not exported+ ;; z: neither defined nor exported+ )+ (import foo '[y x z]) ;; failed imports appear sorted in error message+ |]+ prog `failsWith` OtherError "import: cannot import undefined symbols: y, z"]wherefailsWith src err = noStack (runPureCode src) @?= Left err