Skip to content

Commit 3b89aae

Browse files
committed
[fix:Analyser] always getTypeOfExpr VariableUsage
1 parent 1695965 commit 3b89aae

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

example.axl

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
(def text1 "If I have ")
1111
(def text2 " apples to everyone, i'll be left with ")
1212

13-
// This is a comment
1413
(defun arbitrary-function [(initial: int)] {
1514
(print "expressions are written in braces")
1615
(print "and the last value is returned!")

src/Analyser/Analyser.hs

+6-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import qualified Data.HashTable.IO as H
2929
import Data.Maybe (fromJust, fromMaybe, isJust)
3030
import Data.Text as T (Text, empty, pack, toLower, unpack)
3131
import Parser.Ast
32-
( Expr (ArbitraryBlock, Array, Conditional, FunctionCall, FunctionDef, Nil, Root, VariableDef),
32+
( Expr (ArbitraryBlock, Array, Conditional, FunctionCall, FunctionDef, Nil, Root, VariableDef, VariableUsage),
3333
VDataType (Bool, Function, Inferred, NilType),
3434
)
3535

@@ -106,6 +106,11 @@ replaceInferredVdt (VariableDef name Inferred y) gd = do
106106
replaceInferredVdt (FunctionCall name args) gd =
107107
getTypeOfExpr (FunctionCall name args) gd >>= \t ->
108108
pure $ Right $ FunctionCall name args
109+
replaceInferredVdt x@(VariableUsage name) gd = do
110+
res <- getTypeOfExpr x gd
111+
case res of
112+
Left err -> pure $ Left err
113+
Right _ -> pure $ Right x
109114
-- send back nodes that don't need type inference
110115
replaceInferredVdt x _ = pure $ Right x
111116

0 commit comments

Comments
 (0)