From 069fbb3c01d8be0940d60e3324213a0cde4a42d5 Mon Sep 17 00:00:00 2001 From: Tadeo Kondrak Date: Fri, 25 Sep 2020 14:12:11 -0600 Subject: Add opaque type syntax --- test/stage1/behavior/type.zig | 13 +++++++++++-- test/stage1/behavior/type_info.zig | 17 ++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/stage1/behavior/type.zig b/test/stage1/behavior/type.zig index 60a23ffa94..53a47228db 100644 --- a/test/stage1/behavior/type.zig +++ b/test/stage1/behavior/type.zig @@ -190,8 +190,17 @@ test "Type.ErrorUnion" { } test "Type.Opaque" { - testing.expect(@Type(.Opaque) != @Type(.Opaque)); - testing.expect(@typeInfo(@Type(.Opaque)) == .Opaque); + const Opaque = @Type(.{ + .Opaque = .{ + .decls = &[_]TypeInfo.Declaration{}, + }, + }); + testing.expect(Opaque != opaque {}); + testing.expectEqualSlices( + TypeInfo.Declaration, + &[_]TypeInfo.Declaration{}, + @typeInfo(Opaque).Opaque.decls, + ); } test "Type.Vector" { diff --git a/test/stage1/behavior/type_info.zig b/test/stage1/behavior/type_info.zig index 8b413bf031..e663284d0d 100644 --- a/test/stage1/behavior/type_info.zig +++ b/test/stage1/behavior/type_info.zig @@ -199,7 +199,7 @@ fn testUnion() void { expect(typeinfo_info.Union.tag_type.? == TypeId); expect(typeinfo_info.Union.fields.len == 25); expect(typeinfo_info.Union.fields[4].field_type == @TypeOf(@typeInfo(u8).Int)); - expect(typeinfo_info.Union.decls.len == 21); + expect(typeinfo_info.Union.decls.len == 22); const TestNoTagUnion = union { Foo: void, @@ -265,6 +265,21 @@ const TestStruct = packed struct { const Self = @This(); }; +test "type info: opaque info" { + testOpaque(); + comptime testOpaque(); +} + +fn testOpaque() void { + const Foo = opaque { + const A = 1; + fn b() void {} + }; + + const foo_info = @typeInfo(Foo); + expect(foo_info.Opaque.decls.len == 2); +} + test "type info: function type info" { // wasm doesn't support align attributes on functions if (builtin.arch == .wasm32 or builtin.arch == .wasm64) return error.SkipZigTest; -- cgit v1.2.3 From 2b4b03d301ee12126f3bb5ce1d350bac7ad48b84 Mon Sep 17 00:00:00 2001 From: Tadeo Kondrak Date: Fri, 25 Sep 2020 14:29:03 -0600 Subject: Update zig files for opaque type syntax --- lib/std/c.zig | 4 +- lib/std/os/linux/bpf/kern.zig | 50 +++++------ lib/std/os/uefi.zig | 6 +- lib/std/os/uefi/protocols/hii.zig | 2 +- lib/std/os/windows/bits.zig | 30 +++---- lib/std/os/windows/ws2_32.zig | 2 +- src/clang.zig | 172 +++++++++++++++++++------------------- test/compile_errors.zig | 26 +++--- test/gen_h.zig | 2 +- test/stage1/behavior/misc.zig | 6 +- test/translate_c.zig | 14 ++-- 11 files changed, 157 insertions(+), 157 deletions(-) (limited to 'test') diff --git a/lib/std/c.zig b/lib/std/c.zig index 7cfc44714f..a75fcaa84b 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -329,8 +329,8 @@ pub extern "c" fn pthread_cond_signal(cond: *pthread_cond_t) c_int; pub extern "c" fn pthread_cond_broadcast(cond: *pthread_cond_t) c_int; pub extern "c" fn pthread_cond_destroy(cond: *pthread_cond_t) c_int; -pub const pthread_t = *@Type(.Opaque); -pub const FILE = @Type(.Opaque); +pub const pthread_t = *opaque {}; +pub const FILE = opaque {}; pub extern "c" fn dlopen(path: [*:0]const u8, mode: c_int) ?*c_void; pub extern "c" fn dlclose(handle: *c_void) c_int; diff --git a/lib/std/os/linux/bpf/kern.zig b/lib/std/os/linux/bpf/kern.zig index 3bd605301a..a2e9d36aa1 100644 --- a/lib/std/os/linux/bpf/kern.zig +++ b/lib/std/os/linux/bpf/kern.zig @@ -12,28 +12,28 @@ const in_bpf_program = switch (std.builtin.arch) { pub const helpers = if (in_bpf_program) @import("helpers.zig") else struct {}; -pub const BpfSock = @Type(.Opaque); -pub const BpfSockAddr = @Type(.Opaque); -pub const FibLookup = @Type(.Opaque); -pub const MapDef = @Type(.Opaque); -pub const PerfEventData = @Type(.Opaque); -pub const PerfEventValue = @Type(.Opaque); -pub const PidNsInfo = @Type(.Opaque); -pub const SeqFile = @Type(.Opaque); -pub const SkBuff = @Type(.Opaque); -pub const SkMsgMd = @Type(.Opaque); -pub const SkReusePortMd = @Type(.Opaque); -pub const Sock = @Type(.Opaque); -pub const SockAddr = @Type(.Opaque); -pub const SockOps = @Type(.Opaque); -pub const SockTuple = @Type(.Opaque); -pub const SpinLock = @Type(.Opaque); -pub const SysCtl = @Type(.Opaque); -pub const Tcp6Sock = @Type(.Opaque); -pub const TcpRequestSock = @Type(.Opaque); -pub const TcpSock = @Type(.Opaque); -pub const TcpTimewaitSock = @Type(.Opaque); -pub const TunnelKey = @Type(.Opaque); -pub const Udp6Sock = @Type(.Opaque); -pub const XdpMd = @Type(.Opaque); -pub const XfrmState = @Type(.Opaque); +pub const BpfSock = opaque {}; +pub const BpfSockAddr = opaque {}; +pub const FibLookup = opaque {}; +pub const MapDef = opaque {}; +pub const PerfEventData = opaque {}; +pub const PerfEventValue = opaque {}; +pub const PidNsInfo = opaque {}; +pub const SeqFile = opaque {}; +pub const SkBuff = opaque {}; +pub const SkMsgMd = opaque {}; +pub const SkReusePortMd = opaque {}; +pub const Sock = opaque {}; +pub const SockAddr = opaque {}; +pub const SockOps = opaque {}; +pub const SockTuple = opaque {}; +pub const SpinLock = opaque {}; +pub const SysCtl = opaque {}; +pub const Tcp6Sock = opaque {}; +pub const TcpRequestSock = opaque {}; +pub const TcpSock = opaque {}; +pub const TcpTimewaitSock = opaque {}; +pub const TunnelKey = opaque {}; +pub const Udp6Sock = opaque {}; +pub const XdpMd = opaque {}; +pub const XfrmState = opaque {}; diff --git a/lib/std/os/uefi.zig b/lib/std/os/uefi.zig index 0127033db2..ba1544105c 100644 --- a/lib/std/os/uefi.zig +++ b/lib/std/os/uefi.zig @@ -17,7 +17,7 @@ pub var handle: Handle = undefined; pub var system_table: *tables.SystemTable = undefined; /// A handle to an event structure. -pub const Event = *@Type(.Opaque); +pub const Event = *opaque {}; /// GUIDs must be align(8) pub const Guid = extern struct { @@ -51,7 +51,7 @@ pub const Guid = extern struct { }; /// An EFI Handle represents a collection of related interfaces. -pub const Handle = *@Type(.Opaque); +pub const Handle = *opaque {}; /// This structure represents time information. pub const Time = extern struct { @@ -108,4 +108,4 @@ pub const TimeCapabilities = extern struct { }; /// File Handle as specified in the EFI Shell Spec -pub const FileHandle = *@Type(.Opaque); +pub const FileHandle = *opaque {}; diff --git a/lib/std/os/uefi/protocols/hii.zig b/lib/std/os/uefi/protocols/hii.zig index 960402828e..ed7c40d6ac 100644 --- a/lib/std/os/uefi/protocols/hii.zig +++ b/lib/std/os/uefi/protocols/hii.zig @@ -6,7 +6,7 @@ const uefi = @import("std").os.uefi; const Guid = uefi.Guid; -pub const HIIHandle = *@Type(.Opaque); +pub const HIIHandle = *opaque {}; /// The header found at the start of each package. pub const HIIPackageHeader = packed struct { diff --git a/lib/std/os/windows/bits.zig b/lib/std/os/windows/bits.zig index d22f42d6e8..bf786d5c91 100644 --- a/lib/std/os/windows/bits.zig +++ b/lib/std/os/windows/bits.zig @@ -32,16 +32,16 @@ pub const UCHAR = u8; pub const FLOAT = f32; pub const HANDLE = *c_void; pub const HCRYPTPROV = ULONG_PTR; -pub const HBRUSH = *@Type(.Opaque); -pub const HCURSOR = *@Type(.Opaque); -pub const HICON = *@Type(.Opaque); -pub const HINSTANCE = *@Type(.Opaque); -pub const HMENU = *@Type(.Opaque); -pub const HMODULE = *@Type(.Opaque); -pub const HWND = *@Type(.Opaque); -pub const HDC = *@Type(.Opaque); -pub const HGLRC = *@Type(.Opaque); -pub const FARPROC = *@Type(.Opaque); +pub const HBRUSH = *opaque {}; +pub const HCURSOR = *opaque {}; +pub const HICON = *opaque {}; +pub const HINSTANCE = *opaque {}; +pub const HMENU = *opaque {}; +pub const HMODULE = *opaque {}; +pub const HWND = *opaque {}; +pub const HDC = *opaque {}; +pub const HGLRC = *opaque {}; +pub const FARPROC = *opaque {}; pub const INT = c_int; pub const LPBYTE = *BYTE; pub const LPCH = *CHAR; @@ -81,7 +81,7 @@ pub const WPARAM = usize; pub const LPARAM = ?*c_void; pub const LRESULT = ?*c_void; -pub const va_list = *@Type(.Opaque); +pub const va_list = *opaque {}; pub const TRUE = 1; pub const FALSE = 0; @@ -1175,10 +1175,10 @@ pub const UNICODE_STRING = extern struct { Buffer: [*]WCHAR, }; -const ACTIVATION_CONTEXT_DATA = @Type(.Opaque); -const ASSEMBLY_STORAGE_MAP = @Type(.Opaque); -const FLS_CALLBACK_INFO = @Type(.Opaque); -const RTL_BITMAP = @Type(.Opaque); +const ACTIVATION_CONTEXT_DATA = opaque {}; +const ASSEMBLY_STORAGE_MAP = opaque {}; +const FLS_CALLBACK_INFO = opaque {}; +const RTL_BITMAP = opaque {}; pub const PRTL_BITMAP = *RTL_BITMAP; const KAFFINITY = usize; diff --git a/lib/std/os/windows/ws2_32.zig b/lib/std/os/windows/ws2_32.zig index ac21b6ffc9..19bfc0d83e 100644 --- a/lib/std/os/windows/ws2_32.zig +++ b/lib/std/os/windows/ws2_32.zig @@ -5,7 +5,7 @@ // and substantial portions of the software. usingnamespace @import("bits.zig"); -pub const SOCKET = *@Type(.Opaque); +pub const SOCKET = *opaque {}; pub const INVALID_SOCKET = @intToPtr(SOCKET, ~@as(usize, 0)); pub const SOCKET_ERROR = -1; diff --git a/src/clang.zig b/src/clang.zig index 2551829084..e93060edc5 100644 --- a/src/clang.zig +++ b/src/clang.zig @@ -1,89 +1,89 @@ const builtin = @import("builtin"); -pub const struct_ZigClangConditionalOperator = @Type(.Opaque); -pub const struct_ZigClangBinaryConditionalOperator = @Type(.Opaque); -pub const struct_ZigClangAbstractConditionalOperator = @Type(.Opaque); -pub const struct_ZigClangAPInt = @Type(.Opaque); -pub const struct_ZigClangAPSInt = @Type(.Opaque); -pub const struct_ZigClangAPFloat = @Type(.Opaque); -pub const struct_ZigClangASTContext = @Type(.Opaque); -pub const struct_ZigClangASTUnit = @Type(.Opaque); -pub const struct_ZigClangArraySubscriptExpr = @Type(.Opaque); -pub const struct_ZigClangArrayType = @Type(.Opaque); -pub const struct_ZigClangAttributedType = @Type(.Opaque); -pub const struct_ZigClangBinaryOperator = @Type(.Opaque); -pub const struct_ZigClangBreakStmt = @Type(.Opaque); -pub const struct_ZigClangBuiltinType = @Type(.Opaque); -pub const struct_ZigClangCStyleCastExpr = @Type(.Opaque); -pub const struct_ZigClangCallExpr = @Type(.Opaque); -pub const struct_ZigClangCaseStmt = @Type(.Opaque); -pub const struct_ZigClangCompoundAssignOperator = @Type(.Opaque); -pub const struct_ZigClangCompoundStmt = @Type(.Opaque); -pub const struct_ZigClangConstantArrayType = @Type(.Opaque); -pub const struct_ZigClangContinueStmt = @Type(.Opaque); -pub const struct_ZigClangDecayedType = @Type(.Opaque); -pub const ZigClangDecl = @Type(.Opaque); -pub const struct_ZigClangDeclRefExpr = @Type(.Opaque); -pub const struct_ZigClangDeclStmt = @Type(.Opaque); -pub const struct_ZigClangDefaultStmt = @Type(.Opaque); -pub const struct_ZigClangDiagnosticOptions = @Type(.Opaque); -pub const struct_ZigClangDiagnosticsEngine = @Type(.Opaque); -pub const struct_ZigClangDoStmt = @Type(.Opaque); -pub const struct_ZigClangElaboratedType = @Type(.Opaque); -pub const struct_ZigClangEnumConstantDecl = @Type(.Opaque); -pub const struct_ZigClangEnumDecl = @Type(.Opaque); -pub const struct_ZigClangEnumType = @Type(.Opaque); -pub const struct_ZigClangExpr = @Type(.Opaque); -pub const struct_ZigClangFieldDecl = @Type(.Opaque); -pub const struct_ZigClangFileID = @Type(.Opaque); -pub const struct_ZigClangForStmt = @Type(.Opaque); -pub const struct_ZigClangFullSourceLoc = @Type(.Opaque); -pub const struct_ZigClangFunctionDecl = @Type(.Opaque); -pub const struct_ZigClangFunctionProtoType = @Type(.Opaque); -pub const struct_ZigClangIfStmt = @Type(.Opaque); -pub const struct_ZigClangImplicitCastExpr = @Type(.Opaque); -pub const struct_ZigClangIncompleteArrayType = @Type(.Opaque); -pub const struct_ZigClangIntegerLiteral = @Type(.Opaque); -pub const struct_ZigClangMacroDefinitionRecord = @Type(.Opaque); -pub const struct_ZigClangMacroExpansion = @Type(.Opaque); -pub const struct_ZigClangMacroQualifiedType = @Type(.Opaque); -pub const struct_ZigClangMemberExpr = @Type(.Opaque); -pub const struct_ZigClangNamedDecl = @Type(.Opaque); -pub const struct_ZigClangNone = @Type(.Opaque); -pub const struct_ZigClangOpaqueValueExpr = @Type(.Opaque); -pub const struct_ZigClangPCHContainerOperations = @Type(.Opaque); -pub const struct_ZigClangParenExpr = @Type(.Opaque); -pub const struct_ZigClangParenType = @Type(.Opaque); -pub const struct_ZigClangParmVarDecl = @Type(.Opaque); -pub const struct_ZigClangPointerType = @Type(.Opaque); -pub const struct_ZigClangPreprocessedEntity = @Type(.Opaque); -pub const struct_ZigClangRecordDecl = @Type(.Opaque); -pub const struct_ZigClangRecordType = @Type(.Opaque); -pub const struct_ZigClangReturnStmt = @Type(.Opaque); -pub const struct_ZigClangSkipFunctionBodiesScope = @Type(.Opaque); -pub const struct_ZigClangSourceManager = @Type(.Opaque); -pub const struct_ZigClangSourceRange = @Type(.Opaque); -pub const ZigClangStmt = @Type(.Opaque); -pub const struct_ZigClangStringLiteral = @Type(.Opaque); -pub const struct_ZigClangStringRef = @Type(.Opaque); -pub const struct_ZigClangSwitchStmt = @Type(.Opaque); -pub const struct_ZigClangTagDecl = @Type(.Opaque); -pub const struct_ZigClangType = @Type(.Opaque); -pub const struct_ZigClangTypedefNameDecl = @Type(.Opaque); -pub const struct_ZigClangTypedefType = @Type(.Opaque); -pub const struct_ZigClangUnaryExprOrTypeTraitExpr = @Type(.Opaque); -pub const struct_ZigClangUnaryOperator = @Type(.Opaque); -pub const struct_ZigClangValueDecl = @Type(.Opaque); -pub const struct_ZigClangVarDecl = @Type(.Opaque); -pub const struct_ZigClangWhileStmt = @Type(.Opaque); -pub const struct_ZigClangFunctionType = @Type(.Opaque); -pub const struct_ZigClangPredefinedExpr = @Type(.Opaque); -pub const struct_ZigClangInitListExpr = @Type(.Opaque); -pub const ZigClangPreprocessingRecord = @Type(.Opaque); -pub const ZigClangFloatingLiteral = @Type(.Opaque); -pub const ZigClangConstantExpr = @Type(.Opaque); -pub const ZigClangCharacterLiteral = @Type(.Opaque); -pub const ZigClangStmtExpr = @Type(.Opaque); +pub const struct_ZigClangConditionalOperator = opaque {}; +pub const struct_ZigClangBinaryConditionalOperator = opaque {}; +pub const struct_ZigClangAbstractConditionalOperator = opaque {}; +pub const struct_ZigClangAPInt = opaque {}; +pub const struct_ZigClangAPSInt = opaque {}; +pub const struct_ZigClangAPFloat = opaque {}; +pub const struct_ZigClangASTContext = opaque {}; +pub const struct_ZigClangASTUnit = opaque {}; +pub const struct_ZigClangArraySubscriptExpr = opaque {}; +pub const struct_ZigClangArrayType = opaque {}; +pub const struct_ZigClangAttributedType = opaque {}; +pub const struct_ZigClangBinaryOperator = opaque {}; +pub const struct_ZigClangBreakStmt = opaque {}; +pub const struct_ZigClangBuiltinType = opaque {}; +pub const struct_ZigClangCStyleCastExpr = opaque {}; +pub const struct_ZigClangCallExpr = opaque {}; +pub const struct_ZigClangCaseStmt = opaque {}; +pub const struct_ZigClangCompoundAssignOperator = opaque {}; +pub const struct_ZigClangCompoundStmt = opaque {}; +pub const struct_ZigClangConstantArrayType = opaque {}; +pub const struct_ZigClangContinueStmt = opaque {}; +pub const struct_ZigClangDecayedType = opaque {}; +pub const ZigClangDecl = opaque {}; +pub const struct_ZigClangDeclRefExpr = opaque {}; +pub const struct_ZigClangDeclStmt = opaque {}; +pub const struct_ZigClangDefaultStmt = opaque {}; +pub const struct_ZigClangDiagnosticOptions = opaque {}; +pub const struct_ZigClangDiagnosticsEngine = opaque {}; +pub const struct_ZigClangDoStmt = opaque {}; +pub const struct_ZigClangElaboratedType = opaque {}; +pub const struct_ZigClangEnumConstantDecl = opaque {}; +pub const struct_ZigClangEnumDecl = opaque {}; +pub const struct_ZigClangEnumType = opaque {}; +pub const struct_ZigClangExpr = opaque {}; +pub const struct_ZigClangFieldDecl = opaque {}; +pub const struct_ZigClangFileID = opaque {}; +pub const struct_ZigClangForStmt = opaque {}; +pub const struct_ZigClangFullSourceLoc = opaque {}; +pub const struct_ZigClangFunctionDecl = opaque {}; +pub const struct_ZigClangFunctionProtoType = opaque {}; +pub const struct_ZigClangIfStmt = opaque {}; +pub const struct_ZigClangImplicitCastExpr = opaque {}; +pub const struct_ZigClangIncompleteArrayType = opaque {}; +pub const struct_ZigClangIntegerLiteral = opaque {}; +pub const struct_ZigClangMacroDefinitionRecord = opaque {}; +pub const struct_ZigClangMacroExpansion = opaque {}; +pub const struct_ZigClangMacroQualifiedType = opaque {}; +pub const struct_ZigClangMemberExpr = opaque {}; +pub const struct_ZigClangNamedDecl = opaque {}; +pub const struct_ZigClangNone = opaque {}; +pub const struct_ZigClangOpaqueValueExpr = opaque {}; +pub const struct_ZigClangPCHContainerOperations = opaque {}; +pub const struct_ZigClangParenExpr = opaque {}; +pub const struct_ZigClangParenType = opaque {}; +pub const struct_ZigClangParmVarDecl = opaque {}; +pub const struct_ZigClangPointerType = opaque {}; +pub const struct_ZigClangPreprocessedEntity = opaque {}; +pub const struct_ZigClangRecordDecl = opaque {}; +pub const struct_ZigClangRecordType = opaque {}; +pub const struct_ZigClangReturnStmt = opaque {}; +pub const struct_ZigClangSkipFunctionBodiesScope = opaque {}; +pub const struct_ZigClangSourceManager = opaque {}; +pub const struct_ZigClangSourceRange = opaque {}; +pub const ZigClangStmt = opaque {}; +pub const struct_ZigClangStringLiteral = opaque {}; +pub const struct_ZigClangStringRef = opaque {}; +pub const struct_ZigClangSwitchStmt = opaque {}; +pub const struct_ZigClangTagDecl = opaque {}; +pub const struct_ZigClangType = opaque {}; +pub const struct_ZigClangTypedefNameDecl = opaque {}; +pub const struct_ZigClangTypedefType = opaque {}; +pub const struct_ZigClangUnaryExprOrTypeTraitExpr = opaque {}; +pub const struct_ZigClangUnaryOperator = opaque {}; +pub const struct_ZigClangValueDecl = opaque {}; +pub const struct_ZigClangVarDecl = opaque {}; +pub const struct_ZigClangWhileStmt = opaque {}; +pub const struct_ZigClangFunctionType = opaque {}; +pub const struct_ZigClangPredefinedExpr = opaque {}; +pub const struct_ZigClangInitListExpr = opaque {}; +pub const ZigClangPreprocessingRecord = opaque {}; +pub const ZigClangFloatingLiteral = opaque {}; +pub const ZigClangConstantExpr = opaque {}; +pub const ZigClangCharacterLiteral = opaque {}; +pub const ZigClangStmtExpr = opaque {}; pub const ZigClangBO = extern enum { PtrMemD, @@ -749,11 +749,11 @@ pub const ZigClangCharacterLiteral_CharacterKind = extern enum { }; pub const ZigClangRecordDecl_field_iterator = extern struct { - opaque: *c_void, + ptr: *c_void, }; pub const ZigClangEnumDecl_enumerator_iterator = extern struct { - opaque: *c_void, + ptr: *c_void, }; pub const ZigClangPreprocessingRecord_iterator = extern struct { diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 816d569b4d..f19e3c44c1 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -180,7 +180,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ .layout = .Auto, \\ .tag_type = null, \\ .fields = &[_]TypeInfo.UnionField{ - \\ .{ .name = "foo", .field_type = @Type(.Opaque), .alignment = 1 }, + \\ .{ .name = "foo", .field_type = opaque {}, .alignment = 1 }, \\ }, \\ .decls = &[_]TypeInfo.Declaration{}, \\ }, @@ -2613,7 +2613,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { }); cases.add("directly embedding opaque type in struct and union", - \\const O = @Type(.Opaque); + \\const O = opaque {}; \\const Foo = struct { \\ o: O, \\}; @@ -2628,7 +2628,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ var bar: Bar = undefined; \\} \\export fn c() void { - \\ var baz: *@Type(.Opaque) = undefined; + \\ var baz: *opaque {} = undefined; \\ const qux = .{baz.*}; \\} , &[_][]const u8{ @@ -3592,7 +3592,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { }); cases.add("unknown length pointer to opaque", - \\export const T = [*]@Type(.Opaque); + \\export const T = [*]opaque {}; , &[_][]const u8{ "tmp.zig:1:21: error: unknown-length pointer to opaque", }); @@ -6827,8 +6827,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { "tmp.zig:2:31: error: index 2 outside array of size 2", }); - cases.add("wrong pointer coerced to pointer to @Type(.Opaque)", - \\const Derp = @Type(.Opaque); + cases.add("wrong pointer coerced to pointer to opaque {}", + \\const Derp = opaque {}; \\extern fn bar(d: *Derp) void; \\export fn foo() void { \\ var x = @as(u8, 1); @@ -6854,8 +6854,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry5() void { \\ var d = null; \\} - \\export fn entry6(opaque: *Opaque) void { - \\ var e = opaque.*; + \\export fn entry6(opaque_: *Opaque) void { + \\ var e = opaque_.*; \\} \\export fn entry7() void { \\ var f = i32; @@ -6866,7 +6866,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry9() void { \\ var z: noreturn = return; \\} - \\const Opaque = @Type(.Opaque); + \\const Opaque = opaque {}; \\const Foo = struct { \\ fn bar(self: *const Foo) void {} \\}; @@ -7020,7 +7020,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { }); cases.add("field access of opaque type", - \\const MyType = @Type(.Opaque); + \\const MyType = opaque {}; \\ \\export fn entry() bool { \\ var x: i32 = 1; @@ -7623,7 +7623,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { }); cases.add("function returning opaque type", - \\const FooType = @Type(.Opaque); + \\const FooType = opaque {}; \\export fn bar() !FooType { \\ return error.InvalidValue; \\} @@ -7641,7 +7641,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { }); cases.add("generic function returning opaque type", - \\const FooType = @Type(.Opaque); + \\const FooType = opaque {}; \\fn generic(comptime T: type) !T { \\ return undefined; \\} @@ -7665,7 +7665,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { }); cases.add("function parameter is opaque", - \\const FooType = @Type(.Opaque); + \\const FooType = opaque {}; \\export fn entry1() void { \\ const someFuncPtr: fn (FooType) void = undefined; \\} diff --git a/test/gen_h.zig b/test/gen_h.zig index 7a86d914d7..2122558079 100644 --- a/test/gen_h.zig +++ b/test/gen_h.zig @@ -74,7 +74,7 @@ pub fn addCases(cases: *tests.GenHContext) void { }); cases.add("declare opaque type", - \\const Foo = @Type(.Opaque); + \\const Foo = opaque {}; \\ \\export fn entry(foo: ?*Foo) void { } , &[_][]const u8{ diff --git a/test/stage1/behavior/misc.zig b/test/stage1/behavior/misc.zig index a71d6f86f3..04087dd4af 100644 --- a/test/stage1/behavior/misc.zig +++ b/test/stage1/behavior/misc.zig @@ -438,8 +438,8 @@ export fn writeToVRam() void { vram[0] = 'X'; } -const OpaqueA = @Type(.Opaque); -const OpaqueB = @Type(.Opaque); +const OpaqueA = opaque {}; +const OpaqueB = opaque {}; test "opaque types" { expect(*OpaqueA != *OpaqueB); expect(mem.eql(u8, @typeName(OpaqueA), "OpaqueA")); @@ -704,7 +704,7 @@ test "auto created variables have correct alignment" { comptime expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a); } -extern var opaque_extern_var: @Type(.Opaque); +extern var opaque_extern_var: opaque {}; var var_to_export: u32 = 42; test "extern variable with non-pointer opaque type" { @export(var_to_export, .{ .name = "opaque_extern_var" }); diff --git a/test/translate_c.zig b/test/translate_c.zig index 83fdda8d81..812b3620f0 100644 --- a/test/translate_c.zig +++ b/test/translate_c.zig @@ -121,9 +121,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\struct foo { int x; int y[]; }; \\struct bar { int x; int y[0]; }; , &[_][]const u8{ - \\pub const struct_foo = @Type(.Opaque); + \\pub const struct_foo = opaque {}; , - \\pub const struct_bar = @Type(.Opaque); + \\pub const struct_bar = opaque {}; }); cases.add("nested loops without blocks", @@ -191,7 +191,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub const struct_arcan_shmif_page = // , \\warning: unsupported type: 'Atomic' - \\ @Type(.Opaque); // + \\ opaque {}; // , \\ warning: struct demoted to opaque type - unable to translate type of field abufused , // TODO should be `addr: *struct_arcan_shmif_page` @@ -370,8 +370,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ struct opaque_2 *cast = (struct opaque_2 *)opaque; \\} , &[_][]const u8{ - \\pub const struct_opaque = @Type(.Opaque); - \\pub const struct_opaque_2 = @Type(.Opaque); + \\pub const struct_opaque = opaque {}; + \\pub const struct_opaque_2 = opaque {}; \\pub export fn function(arg_opaque_1: ?*struct_opaque) void { \\ var opaque_1 = arg_opaque_1; \\ var cast: ?*struct_opaque_2 = @ptrCast(?*struct_opaque_2, opaque_1); @@ -612,7 +612,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ struct Foo *foo; \\}; , &[_][]const u8{ - \\pub const struct_Foo = @Type(.Opaque); + \\pub const struct_Foo = opaque {}; , \\pub const struct_Bar = extern struct { \\ foo: ?*struct_Foo, @@ -689,7 +689,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\struct Foo; \\struct Foo *some_func(struct Foo *foo, int x); , &[_][]const u8{ - \\pub const struct_Foo = @Type(.Opaque); + \\pub const struct_Foo = opaque {}; , \\pub extern fn some_func(foo: ?*struct_Foo, x: c_int) ?*struct_Foo; , -- cgit v1.2.3 From d71f339395f8a3a3c09bbb2d51e6f35cb5295d14 Mon Sep 17 00:00:00 2001 From: Tadeo Kondrak Date: Fri, 25 Sep 2020 17:14:13 -0600 Subject: stage1: disallow fields in opaque types --- src/stage1/analyze.cpp | 16 ++++++++++++---- test/compile_errors.zig | 10 ++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/src/stage1/analyze.cpp b/src/stage1/analyze.cpp index 6008496fe2..b22f0ef393 100644 --- a/src/stage1/analyze.cpp +++ b/src/stage1/analyze.cpp @@ -3457,10 +3457,18 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { } static Error resolve_opaque_type(CodeGen *g, ZigType *opaque_type) { - opaque_type->abi_align = UINT32_MAX; - opaque_type->abi_size = SIZE_MAX; - opaque_type->size_in_bits = SIZE_MAX; - return ErrorNone; + Error err = ErrorNone; + AstNode *container_node = opaque_type->data.opaque.decl_node; + if (container_node != nullptr) { + assert(container_node->type == NodeTypeContainerDecl); + AstNodeContainerDecl *container_decl = &container_node->data.container_decl; + for (int i = 0; i < container_decl->fields.length; i++) { + AstNode *field_node = container_decl->fields.items[i]; + add_node_error(g, field_node, buf_create_from_str("opaque types cannot have fields")); + err = ErrorSemanticAnalyzeFail; + } + } + return err; } void append_namespace_qualification(CodeGen *g, Buf *buf, ZigType *container_type) { diff --git a/test/compile_errors.zig b/test/compile_errors.zig index f19e3c44c1..6c2e96fc5e 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -125,6 +125,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { "tmp.zig:15:23: error: enum field missing: 'arst'", "tmp.zig:27:24: note: referenced here", }); + + cases.add("opaque type with field", + \\const Opaque = opaque { foo: i32 }; + \\export fn entry() void { + \\ const foo: ?*Opaque = null; + \\} + , &[_][]const u8{ + "tmp.zig:1:25: error: opaque types cannot have fields", + }); + cases.add("@Type(.Fn) with is_generic = true", \\const Foo = @Type(.{ \\ .Fn = .{ -- cgit v1.2.3 From bf4bfe54ac13512d7553a7be83ae19e908e9c294 Mon Sep 17 00:00:00 2001 From: Tadeo Kondrak Date: Sat, 26 Sep 2020 11:55:56 -0600 Subject: Update compile error test for field access of opaque type --- src/stage1/ir.cpp | 2 ++ test/compile_errors.zig | 30 +++++++++++++++--------------- 2 files changed, 17 insertions(+), 15 deletions(-) (limited to 'test') diff --git a/src/stage1/ir.cpp b/src/stage1/ir.cpp index ad58f23ec3..002b7f3c87 100644 --- a/src/stage1/ir.cpp +++ b/src/stage1/ir.cpp @@ -22387,6 +22387,8 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira, prefix_name = "enum "; } else if (bare_struct_type->id == ZigTypeIdUnion) { prefix_name = "union "; + } else if (bare_struct_type->id == ZigTypeIdOpaque) { + prefix_name = "opaque type "; } else { prefix_name = ""; } diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 6c2e96fc5e..d5c4fd3ec1 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -126,6 +126,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { "tmp.zig:27:24: note: referenced here", }); + cases.add("field access of opaque type", + \\const MyType = opaque {}; + \\ + \\export fn entry() bool { + \\ var x: i32 = 1; + \\ return bar(@ptrCast(*MyType, &x)); + \\} + \\ + \\fn bar(x: *MyType) bool { + \\ return x.blah; + \\} + , &[_][]const u8{ + "tmp.zig:9:13: error: no member named 'blah' in opaque type 'MyType'", + }); + cases.add("opaque type with field", \\const Opaque = opaque { foo: i32 }; \\export fn entry() void { @@ -7029,21 +7044,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { "tmp.zig:37:29: error: cannot store runtime value in compile time variable", }); - cases.add("field access of opaque type", - \\const MyType = opaque {}; - \\ - \\export fn entry() bool { - \\ var x: i32 = 1; - \\ return bar(@ptrCast(*MyType, &x)); - \\} - \\ - \\fn bar(x: *MyType) bool { - \\ return x.blah; - \\} - , &[_][]const u8{ - "tmp.zig:9:13: error: type '*MyType' does not support field access", - }); - cases.add("invalid legacy unicode escape", \\export fn entry() void { \\ const a = '\U1234'; -- cgit v1.2.3 From ae161863db544e2db20ba7705bf0ada7d3ce5c94 Mon Sep 17 00:00:00 2001 From: pfg Date: Tue, 6 Oct 2020 22:38:36 -0700 Subject: stage1: improve error messages for missing `try` statements --- src/stage1/ir.cpp | 8 ++++++-- test/compile_errors.zig | 10 +++++----- 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/src/stage1/ir.cpp b/src/stage1/ir.cpp index ebda9b88f6..2ec615f6b4 100644 --- a/src/stage1/ir.cpp +++ b/src/stage1/ir.cpp @@ -20102,7 +20102,7 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr, if (uncasted_value->value->type->id == ZigTypeIdErrorUnion || uncasted_value->value->type->id == ZigTypeIdErrorSet) { - ir_add_error(ira, source_instr, buf_sprintf("error is discarded")); + ir_add_error(ira, source_instr, buf_sprintf("error is discarded. consider using `try`, `catch`, or `if`")); return ira->codegen->invalid_inst_gen; } return ir_const_void(ira, source_instr); @@ -29492,7 +29492,11 @@ static IrInstGen *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira, return ira->codegen->invalid_inst_gen; if (statement_type->id != ZigTypeIdVoid && statement_type->id != ZigTypeIdUnreachable) { - ir_add_error(ira, &instruction->base.base, buf_sprintf("expression value is ignored")); + if(statement_type->id == ZigTypeIdErrorUnion || statement_type->id == ZigTypeIdErrorSet) { + ir_add_error(ira, &instruction->base.base, buf_sprintf("error is ignored. consider using `try`, `catch`, or `if`")); + }else{ + ir_add_error(ira, &instruction->base.base, buf_sprintf("expression value is ignored")); + } } return ir_const_void(ira, &instruction->base.base); diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 816d569b4d..a733240d57 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -2287,7 +2287,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ return error.OutOfMemory; \\} , &[_][]const u8{ - "tmp.zig:2:12: error: error is discarded", + "tmp.zig:2:12: error: error is discarded. consider using `try`, `catch`, or `if`", }); cases.add("volatile on global assembly", @@ -2338,9 +2338,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ return error.Bad; \\} , &[_][]const u8{ - "tmp.zig:2:24: error: expression value is ignored", - "tmp.zig:6:25: error: expression value is ignored", - "tmp.zig:10:25: error: expression value is ignored", + "tmp.zig:2:24: error: error is ignored. consider using `try`, `catch`, or `if`", + "tmp.zig:6:25: error: error is ignored. consider using `try`, `catch`, or `if`", + "tmp.zig:10:25: error: error is ignored. consider using `try`, `catch`, or `if`", }); cases.add("empty while loop body", @@ -6236,7 +6236,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\} \\fn bar() anyerror!i32 { return 0; } , &[_][]const u8{ - "tmp.zig:2:14: error: expression value is ignored", + "tmp.zig:2:14: error: error is ignored. consider using `try`, `catch`, or `if`", }); cases.add("dereference an array", -- cgit v1.2.3 From 0e57f220fb71efefa9c6246818758d9c30994f73 Mon Sep 17 00:00:00 2001 From: Tadeo Kondrak Date: Mon, 5 Oct 2020 16:39:51 -0600 Subject: stage1: Disallow arrays in function parameters or return types Closes #6535. --- src/stage1/analyze.cpp | 51 ++++++++++++++++++++++++++-------------------- src/stage1/analyze.hpp | 8 +++++++- src/stage1/ir.cpp | 4 ++-- test/compile_errors.zig | 13 ++++++++++++ test/stage1/c_abi/cfuncs.c | 18 ---------------- test/stage1/c_abi/main.zig | 11 ---------- 6 files changed, 51 insertions(+), 54 deletions(-) (limited to 'test') diff --git a/src/stage1/analyze.cpp b/src/stage1/analyze.cpp index bc9d265bd1..fb1360727c 100644 --- a/src/stage1/analyze.cpp +++ b/src/stage1/analyze.cpp @@ -1754,7 +1754,7 @@ static Error emit_error_unless_type_allowed_in_packed_union(CodeGen *g, ZigType return emit_error_unless_type_allowed_in_packed_container(g, type_entry, source_node, "union"); } -Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) { +Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, ExternPosition position, bool *result) { Error err; switch (type_entry->id) { case ZigTypeIdInvalid: @@ -1773,8 +1773,10 @@ Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) { case ZigTypeIdAnyFrame: *result = false; return ErrorNone; - case ZigTypeIdOpaque: case ZigTypeIdUnreachable: + *result = position == ExternPositionFunctionReturn; + return ErrorNone; + case ZigTypeIdOpaque: case ZigTypeIdBool: *result = true; return ErrorNone; @@ -1792,23 +1794,27 @@ Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) { return ErrorNone; } case ZigTypeIdVector: - return type_allowed_in_extern(g, type_entry->data.vector.elem_type, result); + return type_allowed_in_extern(g, type_entry->data.vector.elem_type, ExternPositionOther, result); case ZigTypeIdFloat: *result = true; return ErrorNone; case ZigTypeIdArray: - return type_allowed_in_extern(g, type_entry->data.array.child_type, result); + if ((err = type_allowed_in_extern(g, type_entry->data.array.child_type, ExternPositionOther, result))) + return err; + *result = *result && + position != ExternPositionFunctionParameter && + position != ExternPositionFunctionReturn; + return ErrorNone; case ZigTypeIdFn: *result = !calling_convention_allows_zig_types(type_entry->data.fn.fn_type_id.cc); return ErrorNone; case ZigTypeIdPointer: if ((err = type_resolve(g, type_entry, ResolveStatusZeroBitsKnown))) return err; - if (!type_has_bits(g, type_entry)) { - *result = false; - return ErrorNone; - } - *result = true; + bool has_bits; + if ((err = type_has_bits2(g, type_entry, &has_bits))) + return err; + *result = has_bits; return ErrorNone; case ZigTypeIdStruct: *result = type_entry->data.structure.layout == ContainerLayoutExtern || @@ -1820,23 +1826,24 @@ Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) { *result = false; return ErrorNone; } - if (!type_is_nonnull_ptr(g, child_type)) { + bool is_nonnull_ptr; + if ((err = type_is_nonnull_ptr2(g, child_type, &is_nonnull_ptr))) + return err; + if (!is_nonnull_ptr) { *result = false; return ErrorNone; } - return type_allowed_in_extern(g, child_type, result); + return type_allowed_in_extern(g, child_type, ExternPositionOther, result); } case ZigTypeIdEnum: { if ((err = type_resolve(g, type_entry, ResolveStatusZeroBitsKnown))) return err; ZigType *tag_int_type = type_entry->data.enumeration.tag_int_type; - if (type_entry->data.enumeration.has_explicit_tag_type) { - return type_allowed_in_extern(g, tag_int_type, result); - } else { - *result = type_entry->data.enumeration.layout == ContainerLayoutExtern || - type_entry->data.enumeration.layout == ContainerLayoutPacked; - return ErrorNone; - } + if (type_entry->data.enumeration.has_explicit_tag_type) + return type_allowed_in_extern(g, tag_int_type, position, result); + *result = type_entry->data.enumeration.layout == ContainerLayoutExtern || + type_entry->data.enumeration.layout == ContainerLayoutPacked; + return ErrorNone; } case ZigTypeIdUnion: *result = type_entry->data.unionation.layout == ContainerLayoutExtern || @@ -1933,7 +1940,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc if (!calling_convention_allows_zig_types(fn_type_id.cc)) { bool ok_type; - if ((err = type_allowed_in_extern(g, type_entry, &ok_type))) + if ((err = type_allowed_in_extern(g, type_entry, ExternPositionFunctionParameter, &ok_type))) return g->builtin_types.entry_invalid; if (!ok_type) { add_node_error(g, param_node->data.param_decl.type, @@ -2038,7 +2045,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc if ((err = type_resolve(g, fn_type_id.return_type, ResolveStatusSizeKnown))) return g->builtin_types.entry_invalid; bool ok_type; - if ((err = type_allowed_in_extern(g, fn_type_id.return_type, &ok_type))) + if ((err = type_allowed_in_extern(g, fn_type_id.return_type, ExternPositionFunctionReturn, &ok_type))) return g->builtin_types.entry_invalid; if (!ok_type) { add_node_error(g, fn_proto->return_type, @@ -2357,7 +2364,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) { if (struct_type->data.structure.layout == ContainerLayoutExtern) { bool ok_type; - if ((err = type_allowed_in_extern(g, field_type, &ok_type))) { + if ((err = type_allowed_in_extern(g, field_type, ExternPositionOther, &ok_type))) { struct_type->data.structure.resolve_status = ResolveStatusInvalid; return ErrorSemanticAnalyzeFail; } @@ -2612,7 +2619,7 @@ static Error type_is_valid_extern_enum_tag(CodeGen *g, ZigType *ty, bool *result // signed char, a signed integer or an unsigned one. But GCC/Clang allow // other integral types as a compiler extension so let's accomodate them // aswell. - return type_allowed_in_extern(g, ty, result); + return type_allowed_in_extern(g, ty, ExternPositionOther, result); } static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { diff --git a/src/stage1/analyze.hpp b/src/stage1/analyze.hpp index 07601e6dea..d7a67826d5 100644 --- a/src/stage1/analyze.hpp +++ b/src/stage1/analyze.hpp @@ -50,7 +50,13 @@ bool handle_is_ptr(CodeGen *g, ZigType *type_entry); bool type_has_bits(CodeGen *g, ZigType *type_entry); Error type_has_bits2(CodeGen *g, ZigType *type_entry, bool *result); -Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result); +enum ExternPosition { + ExternPositionFunctionParameter, + ExternPositionFunctionReturn, + ExternPositionOther, // array element, struct field, optional element, etc +}; + +Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, ExternPosition position, bool *result); bool ptr_allows_addr_zero(ZigType *ptr_type); // Deprecated, use `type_is_nonnull_ptr2` diff --git a/src/stage1/ir.cpp b/src/stage1/ir.cpp index 5ab667e831..c90f5f6309 100644 --- a/src/stage1/ir.cpp +++ b/src/stage1/ir.cpp @@ -18963,7 +18963,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport break; case ZigTypeIdArray: { bool ok_type; - if ((err = type_allowed_in_extern(ira->codegen, target->value->type->data.array.child_type, &ok_type))) + if ((err = type_allowed_in_extern(ira->codegen, target->value->type->data.array.child_type, ExternPositionOther, &ok_type))) return ira->codegen->invalid_inst_gen; if (!ok_type) { @@ -32745,7 +32745,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { return ErrorSemanticAnalyzeFail; } else if (lazy_ptr_type->ptr_len == PtrLenC) { bool ok_type; - if ((err = type_allowed_in_extern(ira->codegen, elem_type, &ok_type))) + if ((err = type_allowed_in_extern(ira->codegen, elem_type, ExternPositionOther, &ok_type))) return err; if (!ok_type) { ir_add_error(ira, &lazy_ptr_type->elem_type->base, diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 3156876959..44ee58f002 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -2,6 +2,19 @@ const tests = @import("tests.zig"); const std = @import("std"); pub fn addCases(cases: *tests.CompileErrorContext) void { + cases.add("array in c exported function", + \\export fn zig_array(x: [10]u8) void { + \\ expect(std.mem.eql(u8, &x, "1234567890")); + \\} + \\ + \\export fn zig_return_array() [10]u8 { + \\ return "1234567890".*; + \\} + , &[_][]const u8{ + "tmp.zig:1:24: error: parameter of type '[10]u8' not allowed in function with calling convention 'C'", + "tmp.zig:5:30: error: return type '[10]u8' not allowed in function with calling convention 'C'", + }); + cases.add("@Type for exhaustive enum with undefined tag type", \\const TypeInfo = @import("builtin").TypeInfo; \\const Tag = @Type(.{ diff --git a/test/stage1/c_abi/cfuncs.c b/test/stage1/c_abi/cfuncs.c index 0e7bd2906f..0e8204779a 100644 --- a/test/stage1/c_abi/cfuncs.c +++ b/test/stage1/c_abi/cfuncs.c @@ -28,8 +28,6 @@ void zig_ptr(void *); void zig_bool(bool); -void zig_array(uint8_t[10]); - struct BigStruct { uint64_t a; uint64_t b; @@ -97,9 +95,6 @@ void run_c_tests(void) { zig_bool(true); - uint8_t array[10] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'}; - zig_array(array); - { struct BigStruct s = {1, 2, 3, 4, 5}; zig_big_struct(s); @@ -190,19 +185,6 @@ void c_five_floats(float a, float b, float c, float d, float e) { assert_or_panic(e == 5.0); } -void c_array(uint8_t x[10]) { - assert_or_panic(x[0] == '1'); - assert_or_panic(x[1] == '2'); - assert_or_panic(x[2] == '3'); - assert_or_panic(x[3] == '4'); - assert_or_panic(x[4] == '5'); - assert_or_panic(x[5] == '6'); - assert_or_panic(x[6] == '7'); - assert_or_panic(x[7] == '8'); - assert_or_panic(x[8] == '9'); - assert_or_panic(x[9] == '0'); -} - void c_big_struct(struct BigStruct x) { assert_or_panic(x.a == 1); assert_or_panic(x.b == 2); diff --git a/test/stage1/c_abi/main.zig b/test/stage1/c_abi/main.zig index 9090bb481e..18e9858da4 100644 --- a/test/stage1/c_abi/main.zig +++ b/test/stage1/c_abi/main.zig @@ -116,17 +116,6 @@ export fn zig_bool(x: bool) void { expect(x); } -extern fn c_array([10]u8) void; - -test "C ABI array" { - var array: [10]u8 = "1234567890".*; - c_array(array); -} - -export fn zig_array(x: [10]u8) void { - expect(std.mem.eql(u8, &x, "1234567890")); -} - const BigStruct = extern struct { a: u64, b: u64, -- cgit v1.2.3