Skip to content

Unexpected error: duplicate struct field: '0' in translated C code #4181

Closed
@artob

Description

@artob

Screen Shot 2020-01-14 at 21 49 10

The contents of the file duplicate-struct-field-0.zig:

const std = @import("std");
const testing = std.testing;

// zig translate-c api-level.h | head -n8 | pbcopy
pub export fn android_get_device_api_level() c_int {
    var value: [92]u8 = .{
        @bitCast(u8, @truncate(i8, @as(c_int, 0))),
    } ++ .{0} ** 91;
    if (__system_property_get("ro.build.version.sdk", value) < @as(c_int, 1)) return -@as(c_int, 1);
    var api_level: c_int = atoi(value);
    return if (api_level > @as(c_int, 0)) api_level else -@as(c_int, 1);
}

test "error: duplicate struct field: '0'" {
    testing.expect(android_get_device_api_level() == -1);
}

The contents of the file api-level.h:

int android_get_device_api_level() {
  char value[92] = { 0 };
  if (__system_property_get("ro.build.version.sdk", value) < 1) return -1;
  int api_level = atoi(value);
  return (api_level > 0) ? api_level : -1;
}

This is with HEAD built a few weeks ago (2e53425).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorcontributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.frontendTokenization, parsing, AstGen, Sema, and Liveness.translate-cC to Zig source translation feature (@cImport)

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions