| author | |
| committer | |
| log | afe5862111034ea4100b0eea5971e181d70ffc39 |
| tree | 454fcaa87f6f3c50ccac5c038dd5e6e6236fa54a |
| parent | c6791d87d4f49598aab54064df683fc86e97dbd9 |
3 files changed, 43 insertions(+), 3 deletions(-)
src/Module.zig+1| ... | @@ -3550,6 +3550,7 @@ fn semaContainerFn( | ... | @@ -3550,6 +3550,7 @@ fn semaContainerFn( |
| 3550 | mod.comp.work_queue.writeItemAssumeCapacity(.{ .analyze_decl = new_decl }); | 3550 | mod.comp.work_queue.writeItemAssumeCapacity(.{ .analyze_decl = new_decl }); |
| 3551 | } | 3551 | } |
| 3552 | } | 3552 | } |
| 3553 | new_decl.is_pub = fn_proto.visib_token != null; | ||
| 3553 | } | 3554 | } |
| 3554 | } | 3555 | } |
| 3555 | 3556 |
src/Sema.zig+4-2| ... | @@ -4708,7 +4708,8 @@ fn namedFieldPtr( | ... | @@ -4708,7 +4708,8 @@ fn namedFieldPtr( |
| 4708 | .Struct, .Opaque, .Union => { | 4708 | .Struct, .Opaque, .Union => { |
| 4709 | if (child_type.getContainerScope()) |container_scope| { | 4709 | if (child_type.getContainerScope()) |container_scope| { |
| 4710 | if (mod.lookupDeclName(&container_scope.base, field_name)) |decl| { | 4710 | if (mod.lookupDeclName(&container_scope.base, field_name)) |decl| { |
| 4711 | // TODO if !decl.is_pub and inDifferentFiles() "{} is private" | 4711 | if (!decl.is_pub and !(decl.container.file_scope == block.base.namespace().file_scope)) |
| 4712 | return mod.fail(&block.base, src, "'{s}' is private", .{field_name}); | ||
| 4712 | return sema.analyzeDeclRef(block, src, decl); | 4713 | return sema.analyzeDeclRef(block, src, decl); |
| 4713 | } | 4714 | } |
| 4714 | 4715 | ||
| ... | @@ -4736,7 +4737,8 @@ fn namedFieldPtr( | ... | @@ -4736,7 +4737,8 @@ fn namedFieldPtr( |
| 4736 | .Enum => { | 4737 | .Enum => { |
| 4737 | if (child_type.getContainerScope()) |container_scope| { | 4738 | if (child_type.getContainerScope()) |container_scope| { |
| 4738 | if (mod.lookupDeclName(&container_scope.base, field_name)) |decl| { | 4739 | if (mod.lookupDeclName(&container_scope.base, field_name)) |decl| { |
| 4739 | // TODO if !decl.is_pub and inDifferentFiles() "{} is private" | 4740 | if (!decl.is_pub and !(decl.container.file_scope == block.base.namespace().file_scope)) |
| 4741 | return mod.fail(&block.base, src, "'{s}' is private", .{field_name}); | ||
| 4740 | return sema.analyzeDeclRef(block, src, decl); | 4742 | return sema.analyzeDeclRef(block, src, decl); |
| 4741 | } | 4743 | } |
| 4742 | } | 4744 | } |
test/stage2/test.zig+38-1| ... | @@ -1048,7 +1048,7 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -1048,7 +1048,7 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1048 | "Hello, World!\n", | 1048 | "Hello, World!\n", |
| 1049 | ); | 1049 | ); |
| 1050 | try case.files.append(.{ | 1050 | try case.files.append(.{ |
| 1051 | .src = | 1051 | .src = |
| 1052 | \\pub fn print() void { | 1052 | \\pub fn print() void { |
| 1053 | \\ asm volatile ("syscall" | 1053 | \\ asm volatile ("syscall" |
| 1054 | \\ : | 1054 | \\ : |
| ... | @@ -1064,6 +1064,43 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -1064,6 +1064,43 @@ pub fn addCases(ctx: *TestContext) !void { |
| 1064 | .path = "print.zig", | 1064 | .path = "print.zig", |
| 1065 | }); | 1065 | }); |
| 1066 | } | 1066 | } |
| 1067 | { | ||
| 1068 | var case = ctx.exe("import private", linux_x64); | ||
| 1069 | case.addError( | ||
| 1070 | \\export fn _start() noreturn { | ||
| 1071 | \\ @import("print.zig").print(); | ||
| 1072 | \\ exit(); | ||
| 1073 | \\} | ||
| 1074 | \\ | ||
| 1075 | \\fn exit() noreturn { | ||
| 1076 | \\ asm volatile ("syscall" | ||
| 1077 | \\ : | ||
| 1078 | \\ : [number] "{rax}" (231), | ||
| 1079 | \\ [arg1] "{rdi}" (@as(usize, 0)) | ||
| 1080 | \\ : "rcx", "r11", "memory" | ||
| 1081 | \\ ); | ||
| 1082 | \\ unreachable; | ||
| 1083 | \\} | ||
| 1084 | , | ||
| 1085 | &.{":2:25: error: 'print' is private"}, | ||
| 1086 | ); | ||
| 1087 | try case.files.append(.{ | ||
| 1088 | .src = | ||
| 1089 | \\fn print() void { | ||
| 1090 | \\ asm volatile ("syscall" | ||
| 1091 | \\ : | ||
| 1092 | \\ : [number] "{rax}" (@as(usize, 1)), | ||
| 1093 | \\ [arg1] "{rdi}" (@as(usize, 1)), | ||
| 1094 | \\ [arg2] "{rsi}" (@ptrToInt("Hello, World!\n")), | ||
| 1095 | \\ [arg3] "{rdx}" (@as(usize, 14)) | ||
| 1096 | \\ : "rcx", "r11", "memory" | ||
| 1097 | \\ ); | ||
| 1098 | \\ return; | ||
| 1099 | \\} | ||
| 1100 | , | ||
| 1101 | .path = "print.zig", | ||
| 1102 | }); | ||
| 1103 | } | ||
| 1067 | 1104 | ||
| 1068 | ctx.compileError("function redefinition", linux_x64, | 1105 | ctx.compileError("function redefinition", linux_x64, |
| 1069 | \\// dummy comment | 1106 | \\// dummy comment |