diff --git a/src/Juvix/Compiler/Internal/Data/InfoTable.hs b/src/Juvix/Compiler/Internal/Data/InfoTable.hs index a757eaa34d..8029e17d60 100644 --- a/src/Juvix/Compiler/Internal/Data/InfoTable.hs +++ b/src/Juvix/Compiler/Internal/Data/InfoTable.hs @@ -59,12 +59,23 @@ instance Monoid InfoTable where buildTable :: (Foldable f) => f Module -> InfoTable buildTable = mconcatMap buildTable1 +buildTableRepl :: (Foldable f) => Expression -> f Module -> InfoTable +buildTableRepl e = extendWithReplExpression e . buildTable + buildTable1 :: Module -> InfoTable buildTable1 = run . evalState (mempty :: Cache) . buildTable1' buildTable' :: (Members '[State Cache] r, Foldable f) => f Module -> Sem r InfoTable buildTable' = mconcatMap buildTable1' +extendWithReplExpression :: Expression -> InfoTable -> InfoTable +extendWithReplExpression e = + over + infoFunctions + ( HashMap.union + (HashMap.fromList [(f ^. funDefName, FunctionInfo f) | LetFunDef f <- universeBi e]) + ) + -- | moduleName ↦ infoTable type Cache = HashMap Name InfoTable diff --git a/src/Juvix/Compiler/Internal/Translation/FromInternal.hs b/src/Juvix/Compiler/Internal/Translation/FromInternal.hs index 1427323116..b41976629e 100644 --- a/src/Juvix/Compiler/Internal/Translation/FromInternal.hs +++ b/src/Juvix/Compiler/Internal/Translation/FromInternal.hs @@ -45,14 +45,14 @@ arityCheckExpression InternalResult {..} exp = runReader table (ArityChecking.inferReplExpression exp) where table :: InfoTable - table = buildTable _resultModules + table = buildTableRepl exp _resultModules typeCheckExpressionType :: (Members '[Error JuvixError, NameIdGen, Builtins] r) => InternalTypedResult -> Expression -> Sem r TypedExpression -typeCheckExpressionType (InternalTypedResult {..}) exp = +typeCheckExpressionType InternalTypedResult {..} exp = mapError (JuvixError @TypeCheckerError) $ do runReader _resultFunctions @@ -64,7 +64,7 @@ typeCheckExpressionType (InternalTypedResult {..}) exp = $ inferExpression' Nothing exp where table :: InfoTable - table = buildTable _resultModules + table = buildTableRepl exp _resultModules typeCheckExpression :: (Members '[Error JuvixError, NameIdGen, Builtins] r) => diff --git a/tests/smoke/Commands/repl.smoke.yaml b/tests/smoke/Commands/repl.smoke.yaml index 7779f39f2a..42ead7d96b 100644 --- a/tests/smoke/Commands/repl.smoke.yaml +++ b/tests/smoke/Commands/repl.smoke.yaml @@ -118,6 +118,16 @@ tests: Nat exit-status: 0 + - name: eval-let-expression + command: + - juvix + - repl + stdin: "let {x : Nat; x := 2 + 1} in x" + stdout: + contains: + "suc (suc (suc zero))" + exit-status: 0 + - name: load-builtin-bool command: shell: