···6868 | Just mod => pure mod
69697070 let (False) = modns == primNS | _ => addPrimitives
7171-7171+ let freshMC = MC emptyMap Nil 0 CheckAll
7272 let parts = split modns "."
7373 let fn = joinBy "/" parts ++ ".newt"
7474+7575+ -- Dummy for initial load/parse
7676+ let mod = MkModCtx modns "" emptyMap freshMC emptyMap Nil Nil Nil
7777+ modifyTop [ currentMod := mod; hints := emptyMap; ops := emptyMap ]
7878+7479 -- TODO now we can pass in the module name...
7575- (fn,src) <- repo.getFile importFC fn
8080+ Right (fn,src) <- tryError $ repo.getFile importFC fn
8181+ | Left err => reportError err -- TODO maybe want a better FC.
8282+ modifyTop [ currentMod $= [ modSource := src ]]
8383+7684 let (Right toks) = tokenise fn src
7777- | Left err => throwError err
8585+ | Left err => reportError err
78867987 let (Right ((nameFC, modName), ops, toks)) = partialParse fn parseModHeader top.ops toks
8080- | Left (err, toks) => throwError err
8888+ | Left (err, toks) => reportError err
81898290 log 1 $ \ _ => "scan imports for module \{modName}"
8391 let (True) = modns == modName
8484- | _ => throwError $ E nameFC "module name \{show modName} doesn't match file name \{show fn}"
9292+ | _ => reportError $ E nameFC "module name \{show modName} doesn't match file name \{show fn}"
85938694 let (Right (imports, ops, toks)) = partialParse fn parseImports ops toks
8787- | Left (err, toks) => throwError err
9595+ | Left (err, toks) => reportError err
88968997 imported <- for imports $ \case
9098 MkImport fc (nameFC, name') => do
···96104 let imported = snoc imported primNS
9710598106 putStrLn "module \{modName}"
9999- top <- getTop
107107+108108+ -- currentMod has been wiped by imports..
100109 let freshMC = MC emptyMap Nil 0 CheckAll
101110 let mod = MkModCtx modns src emptyMap freshMC emptyMap imported Nil Nil
102111 modifyTop [ currentMod := mod
···105114 ]
106115107116 -- top hints / ops include all directly imported modules
117117+ top <- getTop
108118 for_ imports $ \case
109119 (MkImport fc (nameFC, ns)) => do
110120 let (Just mod) = lookupMap' ns top.modules | _ => error emptyFC "namespace \{show ns} missing"
···135145 logMetas $ reverse $ listValues top.currentMod.modMetaCtx.metas
136146137147 -- print errors (for batch processing case)
138138- for_ top.currentMod.modErrors $ \ err => putStrLn $ showError src err
148148+ for_ (reverse top.currentMod.modErrors) $ \ err => putStrLn $ showError src err
139149140150 -- update modules with result, leave the rest of context in case this is top file
141151 top <- getTop
···144154145155 pure top.currentMod
146156 where
157157+ reportError : Error → M ModContext
158158+ reportError err = do
159159+ addError err
160160+ top <- getTop
161161+ modifyTop [modules $= updateMap modns top.currentMod ]
162162+ pure top.currentMod
163163+147164 tryProcessDecl : String → String → Decl → M Unit
148165 tryProcessDecl src ns decl = do
149166 (Left err) <- tryError $ processDecl ns decl | _ => pure MkUnit
+8-1
tests/BadImport.newt.fail
···11*** Process tests/BadImport.newt
22-ERROR at tests/BadImport.newt:4:8--4:22: error reading tests/Does/Not/Exist.newt: Error: ENOENT: no such file or directory, open 'tests/Does/Not/Exist.newt'
22+module BadImport
33+ERROR at tests/BadImport.newt:4:8--4:22: Error in import Does.Not.Exist
44+55+ -- Error should point to name here
66+ import Does.Not.Exist
77+ ^^^^^^^^^^^^^^
88+99+ERROR at tests/BadImport.newt:1:1--1:1: Compile failed
+8-8
tests/ErrorDup.newt.fail
···11*** Process tests/ErrorDup.newt
22module ErrorDup
33-ERROR at tests/ErrorDup.newt:9:7--9:10: Nat already declared
44- record Nat where
33+ERROR at tests/ErrorDup.newt:5:6--5:9: Nat already declared
44+ data Nat = Z | S Nat
5566- class Nat where
77- ^^^
66+ data Nat = Z | S Nat
77+ ^^^
8899ERROR at tests/ErrorDup.newt:7:8--7:11: Nat already declared
1010 data Nat = Z | S Nat
···1212 record Nat where
1313 ^^^
14141515-ERROR at tests/ErrorDup.newt:5:6--5:9: Nat already declared
1616- data Nat = Z | S Nat
1515+ERROR at tests/ErrorDup.newt:9:7--9:10: Nat already declared
1616+ record Nat where
17171818- data Nat = Z | S Nat
1919- ^^^
1818+ class Nat where
1919+ ^^^
20202121ERROR at tests/ErrorDup.newt:1:1--1:1: Compile failed
+15-1
tests/ImportError.newt.fail
···11*** Process tests/ImportError.newt
22-ERROR at tests/ImportError.newt:5:8--5:12: error reading tests/Blah.newt: Error: ENOENT: no such file or directory, open 'tests/Blah.newt'
22+module Prelude
33+module ImportError
44+ERROR at tests/ImportError.newt:5:8--5:12: Error in import Blah
55+ -- test the FC are right and don't include next line
66+ -- TODO continue on and hit the next one.
77+ import Blah
88+ ^^^^
99+1010+ERROR at tests/ImportError.newt:6:8--6:15: Error in import Foo.Bar
1111+ -- TODO continue on and hit the next one.
1212+ import Blah
1313+ import Foo.Bar
1414+ ^^^^^^^
1515+1616+ERROR at tests/ImportError.newt:1:1--1:1: Compile failed