Fixed some segfaults

This commit is contained in:
Mattia Giambirtone 2022-05-29 23:01:36 +02:00
parent 9dacda4009
commit 50b7b56feb
1 changed files with 6 additions and 3 deletions

View File

@ -463,8 +463,10 @@ proc compareTypes(self: Compiler, a, b: Type): bool =
if a.args.len() != b.args.len(): if a.args.len() != b.args.len():
return false return false
elif not self.compareTypes(a.returnType, b.returnType): elif not self.compareTypes(a.returnType, b.returnType):
if a.returnType.kind != Any and b.returnType.kind != Any: if a.returnType != nil and b.returnType != nil:
return false if a.returnType.kind != Any and b.returnType.kind != Any:
return false
return false
for (argA, argB) in zip(a.args, b.args): for (argA, argB) in zip(a.args, b.args):
if not self.compareTypes(argA.kind, argB.kind): if not self.compareTypes(argA.kind, argB.kind):
return false return false
@ -887,6 +889,7 @@ proc declareName(self: Compiler, node: Declaration) =
isConst: false, isConst: false,
owner: self.currentModule, owner: self.currentModule,
valueType: Type(kind: Function, valueType: Type(kind: Function,
name: node.name.token.lexeme,
returnType: self.inferType( returnType: self.inferType(
node.returnType), node.returnType),
args: @[]), args: @[]),
@ -1321,7 +1324,7 @@ proc varDecl(self: Compiler, node: VarDecl) =
let actual = self.inferType(node.value) let actual = self.inferType(node.value)
if expected == nil and actual == nil: if expected == nil and actual == nil:
self.error(&"'{node.name.token.lexeme}' has no type") 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") self.error(&"invalid type '{self.typeToStr(expected)}' for var")
elif not self.compareTypes(expected, actual): elif not self.compareTypes(expected, actual):
if expected != nil: if expected != nil: