@@ -1051,6 +1051,15 @@ infer_ternary(JikNode *nd)
10511051 jik_diag_fatal_error ("ternary branches have incompatible types" , jik_token_to_text (nd -> token ));
10521052}
10531053
1054+ static char *
1055+ make_binop_error_msg (JikNode * nd )
1056+ {
1057+ return JIK_STRING_NCAT ("unsupported binop between " ,
1058+ jik_type_pretty_name (nd -> val_binop .left -> jik_type ),
1059+ " and " ,
1060+ jik_type_pretty_name (nd -> val_binop .right -> jik_type ));
1061+ }
1062+
10541063static void
10551064infer_binop (JikNode * nd )
10561065{
@@ -1064,7 +1073,7 @@ infer_binop(JikNode *nd)
10641073 // TODO: simpligy this to numeric types or similar
10651074 if (!binop_operands_are_of_type (nd ,
10661075 (JikTypeName []){TYPE_INTEGER , TYPE_FLOAT , TYPE_NOTYPE })) {
1067- jik_diag_fatal_error ("unsupported type for binop" , jik_token_to_text (nd -> token ));
1076+ jik_diag_fatal_error (make_binop_error_msg ( nd ) , jik_token_to_text (nd -> token ));
10681077 }
10691078 if (nd -> val_binop .left -> jik_type == & JIK_TYPE_FLOAT ||
10701079 nd -> val_binop .right -> jik_type == & JIK_TYPE_FLOAT ) {
@@ -1076,15 +1085,15 @@ infer_binop(JikNode *nd)
10761085 }
10771086 else if (strcmp (nd -> val_binop .val , "%" ) == 0 ) {
10781087 if (!binop_operands_are_of_type (nd , (JikTypeName []){TYPE_INTEGER , TYPE_NOTYPE })) {
1079- jik_diag_fatal_error ("unsupported type for binop" , jik_token_to_text (nd -> token ));
1088+ jik_diag_fatal_error (make_binop_error_msg ( nd ) , jik_token_to_text (nd -> token ));
10801089 }
10811090 nd -> jik_type = & JIK_TYPE_INT ;
10821091 }
10831092 else if (strcmp (nd -> val_binop .val , "<" ) == 0 || strcmp (nd -> val_binop .val , ">" ) == 0 ||
10841093 strcmp (nd -> val_binop .val , ">=" ) == 0 || strcmp (nd -> val_binop .val , "<=" ) == 0 ) {
10851094 if (!binop_operands_are_of_type (nd ,
10861095 (JikTypeName []){TYPE_INTEGER , TYPE_FLOAT , TYPE_NOTYPE })) {
1087- jik_diag_fatal_error ("unsupported type for binop" , jik_token_to_text (nd -> token ));
1096+ jik_diag_fatal_error (make_binop_error_msg ( nd ) , jik_token_to_text (nd -> token ));
10881097 }
10891098 nd -> jik_type = & JIK_TYPE_BOOL ;
10901099 }
@@ -1097,18 +1106,18 @@ infer_binop(JikNode *nd)
10971106 TYPE_CHAR ,
10981107 TYPE_ENUM ,
10991108 TYPE_NOTYPE }))
1100- jik_diag_fatal_error ("unsupported type for binop" , jik_token_to_text (nd -> token ));
1109+ jik_diag_fatal_error (make_binop_error_msg ( nd ) , jik_token_to_text (nd -> token ));
11011110 nd -> jik_type = & JIK_TYPE_BOOL ;
11021111 if (binop_operands_are_of_type (nd , (JikTypeName []){TYPE_INTEGER , TYPE_FLOAT , TYPE_NOTYPE }))
11031112 return ;
11041113 if (!jik_node_types_equal (nd -> val_binop .left , nd -> val_binop .right )) {
1105- jik_diag_fatal_error ("binary operator between different types" ,
1114+ jik_diag_fatal_error (make_binop_error_msg ( nd ) ,
11061115 jik_token_to_text (nd -> token ));
11071116 }
11081117 }
11091118 else if (strcmp (nd -> val_binop .val , "and" ) == 0 || strcmp (nd -> val_binop .val , "or" ) == 0 ) {
11101119 if (!binop_operands_are_of_type (nd , (JikTypeName []){TYPE_BOOL , TYPE_NOTYPE })) {
1111- jik_diag_fatal_error ("unsupported type for binop" , jik_token_to_text (nd -> token ));
1120+ jik_diag_fatal_error (make_binop_error_msg ( nd ) , jik_token_to_text (nd -> token ));
11121121 }
11131122 nd -> jik_type = & JIK_TYPE_BOOL ;
11141123 }
0 commit comments