aboutsummaryrefslogtreecommitdiff
path: root/test/behavior
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2023-08-27 17:14:31 -0400
committerAndrew Kelley <andrew@ziglang.org>2023-08-30 16:50:30 -0400
commite2ff486de5f3aceb21730e1feabbaf9b03432660 (patch)
tree2ee27be7108be3486d785554cc63ebd89645eec1 /test/behavior
parent49075d20557994da4eb341e7431de38a6df2088b (diff)
downloadzig-e2ff486de5f3aceb21730e1feabbaf9b03432660.tar.gz
zig-e2ff486de5f3aceb21730e1feabbaf9b03432660.zip
Sema: cleanup `coerceExtra`
* remove unreachable code * remove already handled cases * avoid `InternPool.getCoerced` * add some undef checks * error when converting undef int to float Closes #16987
Diffstat (limited to 'test/behavior')
-rw-r--r--test/behavior/cast.zig13
-rw-r--r--test/behavior/undefined.zig1
2 files changed, 14 insertions, 0 deletions
diff --git a/test/behavior/cast.zig b/test/behavior/cast.zig
index 85d1b28a5a..482720d228 100644
--- a/test/behavior/cast.zig
+++ b/test/behavior/cast.zig
@@ -1155,6 +1155,8 @@ fn foobar(func: PFN_void) !void {
}
test "cast function with an opaque parameter" {
+ if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
+
const Container = struct {
const Ctx = opaque {};
ctx: *Ctx,
@@ -2494,3 +2496,14 @@ test "@intFromBool on vector" {
try S.doTheTest();
try comptime S.doTheTest();
}
+
+test "numeric coercions with undefined" {
+ if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
+ if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
+
+ const from: i32 = undefined;
+ var to: f32 = from;
+ to = @floatFromInt(from);
+ to = 42.0;
+ try expectEqual(@as(f32, 42.0), to);
+}
diff --git a/test/behavior/undefined.zig b/test/behavior/undefined.zig
index 6c99b4bbce..9f134b315f 100644
--- a/test/behavior/undefined.zig
+++ b/test/behavior/undefined.zig
@@ -1,6 +1,7 @@
const std = @import("std");
const builtin = @import("builtin");
const expect = std.testing.expect;
+const expectEqual = std.testing.expectEqual;
const mem = std.mem;
fn initStaticArray() [10]i32 {