Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Juvix/Compiler/Concrete/Data/Scope/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 ::
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) =>
Expand Down
4 changes: 4 additions & 0 deletions test/Scope/Positive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 10 additions & 0 deletions tests/positive/issue2999.juvix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module issue2999;

type T := t;

fun : T :=
namedFun@{
x := t
};

namedFun (x : T) : T := t;
Loading