From 50b7b56febd6ec0411ec23e9107d4445747968ae Mon Sep 17 00:00:00 2001 From: Mattia Giambirtone Date: Sun, 29 May 2022 23:01:36 +0200 Subject: [PATCH] Fixed some segfaults --- src/frontend/compiler.nim | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/frontend/compiler.nim b/src/frontend/compiler.nim index 0d7d425..e5256fe 100644 --- a/src/frontend/compiler.nim +++ b/src/frontend/compiler.nim @@ -463,8 +463,10 @@ proc compareTypes(self: Compiler, a, b: Type): bool = if a.args.len() != b.args.len(): return false elif not self.compareTypes(a.returnType, b.returnType): - if a.returnType.kind != Any and b.returnType.kind != Any: - return false + if a.returnType != nil and b.returnType != nil: + if a.returnType.kind != Any and b.returnType.kind != Any: + return false + return false for (argA, argB) in zip(a.args, b.args): if not self.compareTypes(argA.kind, argB.kind): return false @@ -887,6 +889,7 @@ proc declareName(self: Compiler, node: Declaration) = isConst: false, owner: self.currentModule, valueType: Type(kind: Function, + name: node.name.token.lexeme, returnType: self.inferType( node.returnType), args: @[]), @@ -1321,7 +1324,7 @@ proc varDecl(self: Compiler, node: VarDecl) = let actual = self.inferType(node.value) if expected == nil and actual == nil: self.error(&"'{node.name.token.lexeme}' has no type") - elif expected.kind == Mutable: # I mean, variables *are* already mutable (some of them anyway) + elif expected != nil and expected.kind == Mutable: # I mean, variables *are* already mutable (some of them anyway) self.error(&"invalid type '{self.typeToStr(expected)}' for var") elif not self.compareTypes(expected, actual): if expected != nil: