Added broken check for bool if cond. Also added some wonky if/else pretty printing for AST.
This commit is contained in:
@@ -23,6 +23,8 @@ Semantic_Type :: enum {
|
||||
Texture2D :: 4;
|
||||
Sampler :: 5;
|
||||
|
||||
Bool :: 6;
|
||||
|
||||
Max_Builtin :: Sampler + 1;
|
||||
|
||||
Unit;
|
||||
@@ -488,6 +490,33 @@ Attempting to access a field on a primitive type '%'.
|
||||
|
||||
message := builder_to_string(*builder,, temp);
|
||||
record_error(checker, message, node.source_location, false);
|
||||
|
||||
white(*builder);
|
||||
}
|
||||
|
||||
if_condition_has_to_be_boolean_type :: (checker : *Semantic_Checker, usage_site : *AST_Node, handle : Type_Variable_Handle) {
|
||||
/*
|
||||
Type of expression in if condition has to be bool.
|
||||
if x > 100 {
|
||||
^^^^^^^
|
||||
*/
|
||||
|
||||
builder : String_Builder;
|
||||
init_string_builder(*builder,, temp);
|
||||
|
||||
variable := from_handle(checker, handle);
|
||||
append(*builder, "Type of expression in if condition has to be bool.\n");
|
||||
|
||||
indent(*builder, 1);
|
||||
cyan(*builder);
|
||||
|
||||
print_to_builder(*builder, "%\n", print_from_source_location(usage_site.source_location));
|
||||
indent(*builder, 1);
|
||||
|
||||
message := builder_to_string(*builder,, temp);
|
||||
record_error(checker, message, usage_site.source_location, false);
|
||||
|
||||
white(*builder);
|
||||
}
|
||||
|
||||
type_mismatch :: (checker : *Semantic_Checker, usage_site : *AST_Node, expect_node : *AST_Node, expect : Type_Variable_Handle, got : Type_Variable_Handle) {
|
||||
@@ -1430,12 +1459,33 @@ check_node :: (checker : *Semantic_Checker, node : *AST_Node) -> Type_Variable_H
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
case .TOKEN_GREATER; #through;
|
||||
case .TOKEN_GREATEREQUALS; #through;
|
||||
case .TOKEN_LESS; #through;
|
||||
case .TOKEN_LESSEQUALS; #through;
|
||||
case .TOKEN_LOGICALOR; #through;
|
||||
case .TOKEN_ISEQUAL; #through;
|
||||
case .TOKEN_ISNOTEQUAL; #through;
|
||||
case .TOKEN_LOGICALAND; {
|
||||
variable.type = .Bool;
|
||||
variable.typename = Typenames[variable.type];
|
||||
}
|
||||
}
|
||||
return handle;
|
||||
}
|
||||
case .Return; {
|
||||
return check_node(checker, node.children[0]);
|
||||
}
|
||||
case .If; {
|
||||
cond_var := check_node(checker, node.children[0]);
|
||||
|
||||
if cond_var > 0 {
|
||||
cond := from_handle(checker, cond_var);
|
||||
if cond.type != .Bool {
|
||||
if_condition_has_to_be_boolean_type(checker, node, cond_var);
|
||||
}
|
||||
}
|
||||
}
|
||||
case .Variable; {
|
||||
return create_variable(checker, node);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user