Skip to content

Commit

Permalink
@norecurse added
Browse files Browse the repository at this point in the history
  • Loading branch information
joshring authored and lerno committed Sep 28, 2024
1 parent fc0f1a6 commit 439ed59
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/content/docs/Language Common/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ The return value may not be discarded.

Prevents the compiler from zero initializing the variable.

### @norecurse

*Used for: import <module_name> @norecurse*

Import the module but not sub-modules or parent-modules, see [Modules Section](/language-fundamentals/modules/#non-recursive-imports).

### @noreturn

*Used for: function*
Expand Down
28 changes: 20 additions & 8 deletions src/content/docs/Language Fundamentals/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ An alternative to `$include` is `$exec` which is similar to include, but instead
program as the included text.

An example:
```c
```c3
import std::io;
// On Linux or MacOS this will insert 'String a = "Hello world!";'
Expand Down Expand Up @@ -492,10 +492,10 @@ In specific circumstances you only wish to import a module *without* its submodu
This can be helpful in certain situations where otherwise unnecessary name-collisions
would occur, but should not be used in the general case.

The syntax for non-recursive imports is `import <module_name>^;` for example:
```c
The syntax for non-recursive imports is `import <module_name> @norecurse;` for example:
```c3
// Non-recursive import
import mylib^;
import mylib @norecurse;
// Normal import
import mylib;
Expand All @@ -509,15 +509,15 @@ my_code
└── submod
```

```c
```c3
module mylib;
import std::io;
fn void only_want_this()
{
io::printn("only_want_this");
}
module mylib::submod
module mylib::submod;
import std::io;
fn void undesired_fn()
{
Expand All @@ -526,15 +526,27 @@ fn void undesired_fn()
module my_code;
// Using Non-recursive import undesired_fn not found
import mylib^;
import mylib @norecurse;
// Using Recursive import undesired_fn is found
// import mylib;
fn void main()
{
mylib::only_want_this();
sublib::undesired_fn(); // This should error
submod::undesired_fn(); // This should error
}
```

:::note
You can import multiple modules in one line:
```c3
import lib1, lib2;
```
`@norecurse` can be applied to one of those imports individually:

```c3
import lib1 @norecurse, lib2;
```
Here only `lib1` is imported non-recursively and `lib2` is imported normally, recursively.
:::

0 comments on commit 439ed59

Please sign in to comment.