1
1
mirror of https://github.com/anoma/juvix.git synced 2025-01-05 22:46:08 +03:00

Fix a bug that prevented use of name signature defined after the point (#3001)

- Fixes #2999
This commit is contained in:
Jan Mas Rovira 2024-09-06 14:32:03 +02:00 committed by GitHub
parent e45503a63e
commit 4ae4e4e4d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 28 additions and 11 deletions

View File

@ -59,8 +59,8 @@ data ScoperState = ScoperState
{ -- | Local and top modules currently in scope - used to look up qualified symbols
_scoperModules :: HashMap S.NameId ScopedModule,
_scoperAlias :: HashMap S.NameId PreSymbolEntry,
_scoperSignatures :: HashMap S.NameId (NameSignature 'Parsed),
_scoperScopedSignatures :: HashMap S.NameId (NameSignature 'Scoped),
_scoperScopedNameSignatures :: HashMap S.NameId (NameSignature 'Scoped),
_scoperNameSignatures :: HashMap S.NameId (NameSignature 'Parsed),
-- | Indexed by the inductive type. This is used for record updates
_scoperRecordFields :: HashMap S.NameId RecordInfo,
-- | Indexed by constructor. This is used for record patterns

View File

@ -48,8 +48,8 @@ iniScoperState :: InfoTable -> ScoperState
iniScoperState tab =
ScoperState
{ _scoperModules = mempty,
_scoperSignatures = tab ^. infoParsedNameSigs,
_scoperScopedSignatures = tab ^. infoNameSigs,
_scoperScopedNameSignatures = tab ^. infoNameSigs,
_scoperNameSignatures = tab ^. infoParsedNameSigs,
_scoperRecordFields = tab ^. infoRecords,
_scoperAlias = tab ^. infoScoperAlias,
_scoperConstructorFields = tab ^. infoParsedConstructorSigs,
@ -252,7 +252,7 @@ registerNameSignature ::
Sem r ()
registerNameSignature uid d = do
sig <- mkNameSignature d
modify (set (scoperScopedSignatures . at uid) (Just sig))
modify (set (scoperScopedNameSignatures . at uid) (Just sig))
registerNameSig uid sig
registerConstructorSignature ::
@ -292,7 +292,7 @@ reserveSymbolOfNameSpace ns kind kindPretty nameSig builtin s = do
strat <- ask
s' <- freshSymbol kind kindPretty s
whenJust builtin (`registerBuiltin` s')
whenJust nameSig (modify' . set (scoperSignatures . at (s' ^. S.nameId)) . Just)
whenJust nameSig (modify' . set (scoperNameSignatures . at (s' ^. S.nameId)) . Just)
whenJust nameSig (registerParsedNameSig (s' ^. S.nameId))
modify (set (scopeNameSpaceLocal sns . at s) (Just s'))
registerName s'
@ -2710,7 +2710,10 @@ checkNamedApplicationNew ::
checkNamedApplicationNew napp = do
let nargs = napp ^. namedApplicationNewArguments
aname <- checkScopedIden (napp ^. namedApplicationNewName)
sig <- if null nargs then return $ NameSignature [] else getNameSignature aname
sig :: NameSignature 'Parsed <-
if
| null nargs -> return (NameSignature [])
| otherwise -> getNameSignatureParsed aname
let namesInSignature = hashSet (concatMap (HashMap.keys . (^. nameBlock)) (sig ^. nameSignatureArgs))
forM_ nargs (checkNameInSignature namesInSignature . (^. namedArgumentNewSymbol))
puns <- scopePuns
@ -2873,16 +2876,16 @@ getRecordInfo' loc name nameId =
err :: Sem r a
err = throw (ErrNotARecord (NotARecord name loc))
getNameSignature :: (Members '[State ScoperState, Error ScoperError] r) => ScopedIden -> Sem r (NameSignature 'Scoped)
getNameSignature s = do
getNameSignatureParsed :: (Members '[State ScoperState, Error ScoperError] r) => ScopedIden -> Sem r (NameSignature 'Parsed)
getNameSignatureParsed s = do
sig <- maybeM (throw err) return (lookupNameSignature (s ^. scopedIdenFinal . S.nameId))
when (null (sig ^. nameSignatureArgs)) (throw err)
return sig
where
err = ErrNoNameSignature (NoNameSignature s)
lookupNameSignature :: (Members '[State ScoperState] r) => S.NameId -> Sem r (Maybe (NameSignature 'Scoped))
lookupNameSignature s' = gets (^. scoperScopedSignatures . at s')
lookupNameSignature :: (Members '[State ScoperState] r) => S.NameId -> Sem r (Maybe (NameSignature 'Parsed))
lookupNameSignature s' = gets (^. scoperNameSignatures . at s')
checkIterator ::
(Members '[HighlightBuilder, Reader ScopeParameters, Error ScoperError, State Scope, State ScoperState, InfoTableBuilder, Reader InfoTable, NameIdGen, Reader Package] r) =>

View File

@ -258,6 +258,10 @@ tests =
"Record field iterator"
$(mkRelDir ".")
$(mkRelFile "RecordIterator.juvix"),
posTest
"Forward reference name signature"
$(mkRelDir ".")
$(mkRelFile "issue2999.juvix"),
posTest
"Scan name with 'import' prefix"
$(mkRelDir "issue2929")

View File

@ -0,0 +1,10 @@
module issue2999;
type T := t;
fun : T :=
namedFun@{
x := t
};
namedFun (x : T) : T := t;