added: type check for assignment

This commit is contained in:
Sven Vogel 2024-07-12 20:07:35 +02:00
parent 88e1f061d8
commit 0e03246fc3
1 changed files with 6 additions and 1 deletions

View File

@ -1714,7 +1714,12 @@ int createAssign(Statement *ParentStatement, AST_NODE_PTR currentNode) {
return SEMANTIC_ERROR; return SEMANTIC_ERROR;
} }
// TODO: check assignment type compatability if (!compareTypes(assign.destination->target_type, assign.value->result)) {
print_diagnostic(&assign.value->nodePtr->location, Error, "assignment requires `%s` but got `%s`",
type_to_string(assign.destination->target_type),
type_to_string(assign.value->result));
return SEMANTIC_ERROR;
}
ParentStatement->impl.assignment = assign; ParentStatement->impl.assignment = assign;
return SEMANTIC_OK; return SEMANTIC_OK;