Proper pretty printing and error handling on non-cool if condition.

This commit is contained in:
2025-01-15 21:32:18 +01:00
parent a72a9ff50d
commit b4d119230b
16 changed files with 249 additions and 85 deletions

View File

@@ -52,6 +52,7 @@ Typenames :: string.[
"double" ,
"Texture2D",
"Sampler" ,
"bool" ,
];
Type_Variable :: struct {
@@ -497,8 +498,10 @@ Attempting to access a field on a primitive type '%'.
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 {
if 100.0
^^^^^^^
100.0 has type float
*/
builder : String_Builder;
@@ -510,9 +513,19 @@ if_condition_has_to_be_boolean_type :: (checker : *Semantic_Checker, usage_site
indent(*builder, 1);
cyan(*builder);
print_to_builder(*builder, "%\n", print_from_source_location(usage_site.source_location));
location := usage_site.source_location;
print_to_builder(*builder, "%\n", print_from_source_location(location));
indent(*builder, 1);
print_token_pointer(*builder, usage_site.children[0].source_location.begin);
append(*builder, "\n");
indent(*builder, 1);
var := from_handle(checker, handle);
print_to_builder(*builder, "% has type %\n", print_from_source_location(*usage_site.children[0].source_location), proper_type_to_string(checker, var));
message := builder_to_string(*builder,, temp);
record_error(checker, message, usage_site.source_location, false);