package-private visibility

This commit is contained in:
2026-08-01 22:55:35 +02:00
parent 304880a9aa
commit f267e8c3cb
11 changed files with 301 additions and 185 deletions
+84 -7
View File
@@ -9752,7 +9752,7 @@ hide_is_rejected_outside_named_top_level_declarations :: proc(t: ^testing.T) {
}
@(test)
hide_declarations_are_file_hidden :: proc(t: ^testing.T) {
hide_declarations_are_package_hidden :: proc(t: ^testing.T) {
output := "/tmp/brolang-test-hidden-declarations"
defer _ = os.remove(output)
status := compiler_core.compile_package("examples/packages/hidden_valid/app", output)
@@ -9762,7 +9762,7 @@ hide_declarations_are_file_hidden :: proc(t: ^testing.T) {
}
@(test)
file_hidden_declarations_are_not_package_members :: proc(t: ^testing.T) {
package_hidden_declarations_resolve_locally_but_not_through_imports :: proc(t: ^testing.T) {
sources := source.init_store()
defer source.destroy_store(&sources)
diagnostics := source.init_store_diagnostics(&sources)
@@ -9787,9 +9787,9 @@ file_hidden_declarations_are_not_package_members :: proc(t: ^testing.T) {
found_import = found_import || strings.contains(diagnostic.message, "package 'dep' has no member 'secret'")
found_collision = found_collision || strings.contains(diagnostic.message, "duplicate function 'collision'")
}
testing.expect(t, found_sibling)
testing.expect(t, found_sibling_value)
testing.expect(t, found_sibling_type)
testing.expect(t, !found_sibling)
testing.expect(t, !found_sibling_value)
testing.expect(t, !found_sibling_type)
testing.expect(t, found_import)
testing.expect(t, found_collision)
}
@@ -9910,13 +9910,15 @@ RenamedBox :: alias dep.Box
RenamedPoint :: alias dep.Point
counter :: alias dep.counter
answer :: alias dep.answer
hide local_answer_alias :: alias dep.answer
local_answer func() i32 { return local_answer_alias() }
Scalar :: alias i32
ScalarChain :: alias Scalar
static_scalar Scalar :: Scalar(usize(6))
MaybePoint :: alias ?@dep.Point
Concrete :: alias dep.Box(i32)
`
hidden_text := `dep :: import "../dep"
hide local_answer_alias :: alias dep.answer
`
top_text := `facade :: import "../facade"
Box :: alias facade.RenamedBox
@@ -9946,6 +9948,7 @@ main func() i32 {
`
testing.expect(t, os.write_entire_file(dep_dir + "/dep.bro", transmute([]byte)dep_text))
testing.expect(t, os.write_entire_file(facade_dir + "/facade.bro", transmute([]byte)facade_text))
testing.expect(t, os.write_entire_file(facade_dir + "/hidden.bro", transmute([]byte)hidden_text))
testing.expect(t, os.write_entire_file(top_dir + "/top.bro", transmute([]byte)top_text))
testing.expect(t, os.write_entire_file(app_dir + "/main.bro", transmute([]byte)app_text))
@@ -10083,7 +10086,7 @@ main func() void {}
testing.expect(t, loaded)
wants := []string{
"has no member 'missing'",
"is file-hidden",
"is package-hidden",
"unknown symbol 'nope'",
"unavailable imported package 'gone'",
"package member 'dep.ambiguous' is ambiguous",
@@ -14961,6 +14964,8 @@ enum_field_struct_and_contextual_anonymous_records_compile_and_run :: proc(t: ^t
text := `meta :: import "@std/meta"
testing :: import "@std/testing"
OtherTokenKind :: enum { alpha, beta, end }
TokenKind :: enum(u8) {
ident = 3
int = 8
@@ -15034,6 +15039,8 @@ get func($E, $V type, map @Map(E, V), key E) ?V {
}
main func() i32 {
other Map(OtherTokenKind, []u8) = init(OtherTokenKind, []u8, {alpha = "other"})
if !other.present[0] { return 26 }
_ = ordered
if none != 41 { return 24 }
if !$(static_none == null) or !$(null == static_none) or
@@ -15570,3 +15577,73 @@ main func() void {
testing.expect(t, found_missing)
testing.expect(t, found_empty_c)
}
@(test)
type_factory_inference_prefers_unique_provenance_before_convertible_direct_evidence :: proc(t: ^testing.T) {
directory := "/tmp/brolang-test-factory-provenance-conversion"
main_path := "/tmp/brolang-test-factory-provenance-conversion/main.bro"
output := "/tmp/brolang-test-factory-provenance-conversion-output"
text := `HashBox func($K, $V type, $hash func(value K) usize) type {
return struct { value V }
}
string_hash func(value []u8) usize { return value.len }
StringBox func($V type) type {
return HashBox([]u8, V, string_hash)
}
put func(
$K, $V type,
$hash func(value K) usize,
box @mut HashBox(K, V, hash),
key K,
value V,
) void {
_ = box
_ = key
_ = value
}
main func() i32 {
box StringBox(u32) = {value = 0}
key []mut u8 = undefined
put(&box, key, 42)
return 0
}
`
_ = os2.remove_all(directory)
defer _ = os2.remove_all(directory)
defer _ = os.remove(output)
testing.expect(t, os.make_directory(directory) == nil)
testing.expect(t, os.write_entire_file(main_path, transmute([]byte)text))
testing.expect_value(t, compiler_core.compile_package(
directory, output, nil, target.DEFAULT, cimport.Options{}, ".",
), 0)
state := run_executable(output)
testing.expect_value(t, state.exit_code, 0)
}
@(test)
assertion_location_injection_survives_expression_store_growth :: proc(t: ^testing.T) {
directory := "/tmp/brolang-test-assertion-location-growth"
main_path := "/tmp/brolang-test-assertion-location-growth/main.bro"
output := "/tmp/brolang-test-assertion-location-growth-output"
builder := strings.builder_make()
defer strings.builder_destroy(&builder)
strings.write_string(&builder, "testing :: import \"@std/testing\"\n\nmany test {\n")
for index in 0..<128 {
fmt.sbprintf(&builder, "\ttry testing.expect_equal(%d, %d)\n", index, index)
}
strings.write_string(&builder, "}\n")
_ = os2.remove_all(directory)
defer _ = os2.remove_all(directory)
defer _ = os.remove(output)
testing.expect(t, os.make_directory(directory) == nil)
testing.expect(t, os.write_entire_file(main_path, transmute([]byte)strings.to_string(builder)))
testing.expect_value(t, compiler_core.compile_package(
directory, output, nil, target.DEFAULT, cimport.Options{}, ".", .Test,
), 0)
state := run_executable(output)
testing.expect_value(t, state.exit_code, 0)
}