From ec0224edc3a867bbf059e790ad7b2a1a881a0705 Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 11 Dec 2023 16:13:32 -0800 Subject: Diagnose for invalid decl nesting + namespace lookup fixes. (#3397) * Diagnose for invalid decl nesting. * Fix. * Fix. * Fix. * Fix `namespace` lookup and `using` resolution. * fix project files. * revert project files. * Enhance namespace syntax, docs. * Fixes. --------- Co-authored-by: Yong He --- .../transitive-namespace-import.slang/a.slang | 5 +++ .../transitive-namespace-import.slang/b.slang | 6 ++++ .../transitive-namespace-import.slang/test.slang | 37 ++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 tests/diagnostics/transitive-namespace-import.slang/a.slang create mode 100644 tests/diagnostics/transitive-namespace-import.slang/b.slang create mode 100644 tests/diagnostics/transitive-namespace-import.slang/test.slang (limited to 'tests/diagnostics') diff --git a/tests/diagnostics/transitive-namespace-import.slang/a.slang b/tests/diagnostics/transitive-namespace-import.slang/a.slang new file mode 100644 index 000000000..257bf3717 --- /dev/null +++ b/tests/diagnostics/transitive-namespace-import.slang/a.slang @@ -0,0 +1,5 @@ +module a; +namespace ns +{ + public int fa() { return 1; } +} diff --git a/tests/diagnostics/transitive-namespace-import.slang/b.slang b/tests/diagnostics/transitive-namespace-import.slang/b.slang new file mode 100644 index 000000000..9d33d385d --- /dev/null +++ b/tests/diagnostics/transitive-namespace-import.slang/b.slang @@ -0,0 +1,6 @@ +module b; + +namespace ns +{ + public int f_b() { return 2; } +} diff --git a/tests/diagnostics/transitive-namespace-import.slang/test.slang b/tests/diagnostics/transitive-namespace-import.slang/test.slang new file mode 100644 index 000000000..a60e30a19 --- /dev/null +++ b/tests/diagnostics/transitive-namespace-import.slang/test.slang @@ -0,0 +1,37 @@ +//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK): + +module test; + +import b; + +void testFunc() +{ + // CHECK-NOT: {{.*}}([[# @LINE + 1]]): error + ns.f_b(); // OK. + // CHECK: {{.*}}([[# @LINE + 1]]): error 30027: + ns.f_a(); // Error. +} + +namespace ns +{ + void testFunc2() + { + // CHECK-NOT: {{.*}}([[# @LINE + 1]]): error + f_b(); // OK. + // CHECK: {{.*}}([[# @LINE + 1]]): error 30015: + f_a(); // Error. + } +} + +namespace ns2 +{ + using namespace ns; + + void testFunc3() + { + // CHECK-NOT: {{.*}}([[# @LINE + 1]]): error + f_b(); // OK. + // CHECK: {{.*}}([[# @LINE + 1]]): error 30015: + f_a(); // Error. + } +} -- cgit v1.2.3