commit f980c29306ac9435662bde6fb5557ca0c6d98310 (tree)
parent a438a615e6e2ef9e49bf10405b3ba6c8814ccf4b
Author: Andrew Kelley <andrew@ziglang.org>
Date: Fri, 29 Nov 2019 22:33:55 -0500
fix typo in error note for integer casting
Diffstat:
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/ir.cpp b/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,
diff --git a/test/compile_errors.zig b/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(