summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--code/main.felan14
-rw-r--r--src/compiler/ast-tree.c8
-rw-r--r--src/compiler/ast-tree.h1
3 files changed, 18 insertions, 5 deletions
diff --git a/code/main.felan b/code/main.felan
index e91185a..5ac54dd 100644
--- a/code/main.felan
+++ b/code/main.felan
@@ -6,9 +6,13 @@ float :: f32;
double :: f64;
main :: () -> void {
- a : int = 2;
- if a == 2
- print_u64 1;
- else
- print_u64 0;
+ a :u64= 2;
+ f :: ()->void{
+ print_u64 a;
+ };
+ foo(f);
+};
+
+foo :: (fun:()->void)->void{
+ // fun();
};
diff --git a/src/compiler/ast-tree.c b/src/compiler/ast-tree.c
index 2f9c27c..a0bc974 100644
--- a/src/compiler/ast-tree.c
+++ b/src/compiler/ast-tree.c
@@ -2103,6 +2103,10 @@ AstTreeFunction *getFunction(AstTree *value) {
UNREACHABLE;
}
+bool isFunction(AstTree *value) {
+ return value->type->token == AST_TREE_TOKEN_TYPE_FUNCTION;
+}
+
bool isConst(AstTree *tree, AstTreeHelper *helper) {
switch (tree->token) {
case AST_TREE_TOKEN_TYPE_TYPE:
@@ -2954,6 +2958,10 @@ bool setTypesFunctionCall(AstTree *tree, AstTreeSetTypesHelper helper) {
if (!setAllTypes(metadata->function, helper, NULL)) {
return false;
+ } else if (!isFunction(metadata->function)) {
+ printError(metadata->function->str_begin, metadata->function->str_end,
+ "Object is not a function");
+ return false;
}
AstTreeFunction *function = getFunction(metadata->function);
diff --git a/src/compiler/ast-tree.h b/src/compiler/ast-tree.h
index d6c2523..e12daec 100644
--- a/src/compiler/ast-tree.h
+++ b/src/compiler/ast-tree.h
@@ -235,6 +235,7 @@ AstTree *astTreeParseCurlyBracket(ParserNode *parserNode,
AstTree *astTreeParseParenthesis(ParserNode *parserNode, AstTreeHelper *helper);
AstTreeFunction *getFunction(AstTree *value);
+bool isFunction(AstTree *value);
bool isConst(AstTree *tree, AstTreeHelper *helper);
AstTree *makeTypeOf(AstTree *value);
bool typeIsEqual(const AstTree *type0, const AstTree *type1);