From 11111e5733b189127dc2c4934d67693b9bc6e764 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 6 Dec 2023 12:05:07 -0800 Subject: Support visibility control and default to `internal`. (#3380) * Support visibility control and default to `internal`. * Fix wip. * Fixes. * Fix. * Fix test. * Add legacy language detection and compatibility for existing code. * Add doc. --------- Co-authored-by: Yong He --- .../internal-visibility/that-module-impl.slang | 17 ++++++++++++++ .../internal-visibility/that-module.slang | 25 +++++++++++++++++++++ .../internal-visibility/this-module.slang | 26 ++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 tests/diagnostics/internal-visibility/that-module-impl.slang create mode 100644 tests/diagnostics/internal-visibility/that-module.slang create mode 100644 tests/diagnostics/internal-visibility/this-module.slang (limited to 'tests/diagnostics/internal-visibility') diff --git a/tests/diagnostics/internal-visibility/that-module-impl.slang b/tests/diagnostics/internal-visibility/that-module-impl.slang new file mode 100644 index 000000000..893510afe --- /dev/null +++ b/tests/diagnostics/internal-visibility/that-module-impl.slang @@ -0,0 +1,17 @@ +implementing "that-module"; + + +public void publicFunc2() { } + +internal void internalFunc1() {} + +public struct PublicStruct +{ + int x; + public int y; +} + +public namespace Namespace +{ + public static int publicVar2; +} diff --git a/tests/diagnostics/internal-visibility/that-module.slang b/tests/diagnostics/internal-visibility/that-module.slang new file mode 100644 index 000000000..b072c7231 --- /dev/null +++ b/tests/diagnostics/internal-visibility/that-module.slang @@ -0,0 +1,25 @@ +module "that-module"; + +__include "that-module-impl"; + +void internalMethod(); + +public void publicMethod(); + +public namespace Namespace +{ + static int internalVar; + + public static int publicVar; +} + +enum InternalEnum +{ + A,B,C +} +public enum PublicEnum +{ + D,E,F +} + +struct InternalStruct { int x; } diff --git a/tests/diagnostics/internal-visibility/this-module.slang b/tests/diagnostics/internal-visibility/this-module.slang new file mode 100644 index 000000000..98e0f3d08 --- /dev/null +++ b/tests/diagnostics/internal-visibility/this-module.slang @@ -0,0 +1,26 @@ +//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK): + +module "this-module"; + +import "that-module"; + +void test() +{ + PublicStruct s; + // CHECK:{{.*}}(11): error 30600: + s.x = 1; // Error. + // CHECK-NOT:{{.*}}error + s.y = 2; // OK. + publicMethod(); // OK. + publicFunc2(); // OK. + Namespace.publicVar = 1; // OK. + Namespace.publicVar2 = 1; // OK. + // CHECK:{{.*}}(19): error 30600: + Namespace.internalVar = 1; // error. + // CHECK:{{.*}}(21): error 30600: + InternalEnum e; // Error. + // CHECK:{{.*}}(23): error 30600: + InternalStruct s1; // Error. + // CHECK:{{.*}}(25): error 30600: + internalMethod(); // Error. +} -- cgit v1.2.3