@@ -313,8 +313,8 @@ static int analyze_statement(SemanticInfo *info, AstFunction *fn, SymbolTable *s
313313 if (!is_boolean_like (cond_type ))
314314 {
315315 semantic_error ("while condition in function '%s' must be boolean-compatible but found %s" ,
316- fn -> name ,
317- ast_type_name (cond_type ));
316+ fn -> name ,
317+ ast_type_name (cond_type ));
318318 return 0 ;
319319 }
320320 int loop_has_return = 0 ;
@@ -339,8 +339,8 @@ static int analyze_statement(SemanticInfo *info, AstFunction *fn, SymbolTable *s
339339 if (!is_boolean_like (cond_type ))
340340 {
341341 semantic_error ("for condition in function '%s' must be boolean-compatible but found %s" ,
342- fn -> name ,
343- ast_type_name (cond_type ));
342+ fn -> name ,
343+ ast_type_name (cond_type ));
344344 ok = 0 ;
345345 }
346346 }
@@ -414,7 +414,10 @@ static TypeKind analyze_expression(SemanticInfo *info, SymbolTable *symbols, Ast
414414 switch (expr -> kind )
415415 {
416416 case EXPR_INT_LITERAL :
417- expr -> type = TYPE_INT ;
417+ if (expr -> type != TYPE_CHAR )
418+ {
419+ expr -> type = TYPE_INT ;
420+ }
418421 return expr -> type ;
419422 case EXPR_FLOAT_LITERAL :
420423 expr -> type = TYPE_FLOAT ;
@@ -629,11 +632,11 @@ static int ensure_assignable(TypeKind target, TypeKind value)
629632 {
630633 return target == TYPE_STRING && value == TYPE_STRING ;
631634 }
632- if (target == TYPE_BOOL && (value == TYPE_INT || value == TYPE_FLOAT || value == TYPE_BOOL ))
635+ if (target == TYPE_BOOL && (is_numeric ( value ) || value == TYPE_BOOL ))
633636 {
634637 return 1 ;
635638 }
636- if ((target == TYPE_INT || target == TYPE_FLOAT ) && value == TYPE_BOOL )
639+ if (is_numeric (target ) && value == TYPE_BOOL )
637640 {
638641 return 1 ;
639642 }
@@ -650,12 +653,12 @@ static int ensure_assignable(TypeKind target, TypeKind value)
650653
651654static int is_numeric (TypeKind type )
652655{
653- return type == TYPE_INT || type == TYPE_FLOAT ;
656+ return type == TYPE_INT || type == TYPE_FLOAT || type == TYPE_CHAR ;
654657}
655658
656659static int is_boolean_like (TypeKind type )
657660{
658- return type == TYPE_BOOL || type == TYPE_INT || type == TYPE_FLOAT ;
661+ return type == TYPE_BOOL || type == TYPE_INT || type == TYPE_FLOAT || type == TYPE_CHAR ;
659662}
660663
661664static TypeKind arithmetic_result (TypeKind left , TypeKind right )
0 commit comments