-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@floatToInt with u0 gives misleading error #9415
Labels
bug
Observed behavior contradicts documented or intended behavior
error message
This issue points out an error message that is unhelpful and should be improved.
stage1
The process of building from source via WebAssembly and the C backend.
Milestone
Comments
travisstaloch
referenced
this issue
in greenfork/kisa
Jul 18, 2021
Here is a reproduction which demonstrates how this was discovered. The error message makes it very difficult to tell what caused the error. test "repro std.json.parse error" {
const U = union(enum) { a: u8, b: u0 };
const text = "42";
var tokens = std.json.TokenStream.init(text);
const u = try std.json.parse(U, &tokens, .{});
try std.testing.expectEqual(U{ .a = 42 }, u);
} ..zig/build/lib/zig/std/json.zig:1637:35: error: unable to evaluate constant expression
return @floatToInt(T, float);
^
..zig/build/lib/zig/std/json.zig:1676:38: note: called from here
if (parseInternal(u_field.field_type, token, &tokens_copy, options)) |value| {
^
..zig/build/lib/zig/std/json.zig:1881:32: note: called from here
const r = try parseInternal(T, token, tokens, options);
^
./test.zig:12:33: note: called from here
const u = try std.json.parse(U, &tokens, .{});
^
./test.zig:8:35: note: called from here
test "repro std.json.parse error" {
^
..zig/build/lib/zig/std/json.zig:1637:20: note: referenced here
return @floatToInt(T, float);
|
Vexu
added
bug
Observed behavior contradicts documented or intended behavior
error message
This issue points out an error message that is unhelpful and should be improved.
stage1
The process of building from source via WebAssembly and the C backend.
labels
Aug 6, 2021
In stage1 there are a pile of error messages just giving output "unable to evaluate constant expression": // comptime side effects
static Error ir_exec_scan_for_side_effects(CodeGen *codegen, Stage1Air *exec) {
...
// checking if inlining is not possible
static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, Stage1ZirInst* source_instruction) {
...
//
static Error ir_resolve_const_val(CodeGen *codegen, Stage1Air *exec, AstNode *source_node,
ZigValue *val, UndefAllowed undef_allowed)
...
//
if (!fn_entry || fn_entry->body_node == nullptr) {
ir_add_error(ira, fn_ref, buf_sprintf("unable to evaluate constant expression"));
...
//
if (is_comptime) {
ir_add_error(ira, first_non_const_instruction,
buf_sprintf("unable to evaluate constant expression"));
return ira->codegen->invalid_inst_gen;
}
Although there is a pile of those error message, this requires special casing each of them which is likely not worth the effort in stage1. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
bug
Observed behavior contradicts documented or intended behavior
error message
This issue points out an error message that is unhelpful and should be improved.
stage1
The process of building from source via WebAssembly and the C backend.
This was discovered by @greenfork when trying to call
std.json.parse
passing a union which contains au0
field. Doing so caused an error here in std.json:@g-w1 on discord suggested the error message should be: "error: integer value '1' cannot be stored in type 'u0'"
The text was updated successfully, but these errors were encountered: