Commit f980c29306

Andrew Kelley <andrew@ziglang.org>
2019-11-30 04:33:55
fix typo in error note for integer casting
1 parent a438a61
Changed files (2)
src/ir.cpp
@@ -12753,7 +12753,7 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa
             ZigType *wanted_type = cast_result->data.int_shorten->wanted_type;
             ZigType *actual_type = cast_result->data.int_shorten->actual_type;
             const char *wanted_signed = wanted_type->data.integral.is_signed ? "signed" : "unsigned";
-            const char *actual_signed = wanted_type->data.integral.is_signed ? "signed" : "unsigned";
+            const char *actual_signed = actual_type->data.integral.is_signed ? "signed" : "unsigned";
             add_error_note(ira->codegen, parent_msg, source_node,
                 buf_sprintf("%s %" PRIu32 "-bit int cannot represent all possible %s %" PRIu32 "-bit values",
                     wanted_signed, wanted_type->data.integral.bit_count,
test/compile_errors.zig
@@ -1644,11 +1644,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
         \\    var spartan_count: u16 = 300;
         \\    var byte: u8 = spartan_count;
         \\}
+        \\export fn entry4() void {
+        \\    var signed: i8 = -1;
+        \\    var unsigned: u64 = signed;
+        \\}
     ,
         "tmp.zig:3:31: error: integer value 300 cannot be coerced to type 'u8'",
         "tmp.zig:7:22: error: integer value 300 cannot be coerced to type 'u8'",
         "tmp.zig:11:20: error: expected type 'u8', found 'u16'",
         "tmp.zig:11:20: note: unsigned 8-bit int cannot represent all possible unsigned 16-bit values",
+        "tmp.zig:15:25: error: expected type 'u64', found 'i8'",
+        "tmp.zig:15:25: note: unsigned 64-bit int cannot represent all possible signed 8-bit values",
     );
 
     cases.add(