Don't crash on undefined names.

When we resolve an undfined name we record error, but we continue
processing things, so that we can report multiple errors.  As a result
we need to generate some sort of fake "real" name for the undefined entity.

Previously we used to generate a fake local name, but that confused parts
of the code that expected certain things to always be defined at the top
level.  So now we generate a fake name in the Cryptol prelude instead.
This commit is contained in:
Iavor Diatchki 2022-06-14 09:26:59 -07:00
parent 6ab14706af
commit 1e3ad37127
5 changed files with 18 additions and 2 deletions

View File

@ -52,7 +52,7 @@ import Cryptol.Parser.AST
import Cryptol.Parser.Selector(selName)
import Cryptol.Utils.Panic (panic)
import Cryptol.Utils.RecordMap
import Cryptol.Utils.Ident(allNamespaces,OrigName(..),modPathCommon)
import Cryptol.Utils.Ident(allNamespaces,OrigName(..),modPathCommon,preludeName)
import Cryptol.Utils.PP
import Cryptol.ModuleSystem.Interface
@ -643,6 +643,7 @@ instance Rename TopDecl where
renI :: Located (ImportG (ImpName PName)) ->
RenameM (Located (ImportG (ImpName Name)))
renI li =
withLoc (srcRange li)
do m <- rename (iModule i)
recordImport (srcRange li) m
pure li { thing = i { iModule = m } }
@ -838,7 +839,8 @@ renameType nt = resolveName nt NSType
mkFakeName :: Namespace -> PName -> RenameM Name
mkFakeName ns pn =
do ro <- RenameM ask
liftSupply (mkLocal ns (getIdent pn) (roLoc ro))
liftSupply (mkDeclared ns (TopModule preludeName) SystemName (getIdent pn)
Nothing (roLoc ro))
-- | Rename a schema, assuming that none of its type variables are already in
-- scope.

View File

@ -0,0 +1,2 @@
import T16_M
import submodule A

View File

@ -0,0 +1 @@
:load T16.cry

View File

@ -0,0 +1,7 @@
Loading module Cryptol
Loading module Cryptol
Loading module T16_M
Loading module Main
[error] at T16.cry:2:1--2:19
Module not in scope: A

View File

@ -0,0 +1,4 @@
module T16_M where
private
submodule A where
x = 0x02