You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For 3.8, we added support for nested module syntax:
moduleFoo::Bar {...}
This is great, but it introduces some unfortunate ambiguity with how metadata applies to this syntax.
For example, if you write:
["something"]
moduleFoo::Bar {}
I think there are really 3 separate ways to interpret this:
Metadata applies to the innermost module (Bar)
Metadata applies to the outermost module (Foo)
Metadata applies to the entire construct (Foo::Bar)
I think all 3 of these are valid intuitive beliefs. So no matter which we pick, some users will be surprised, and all users will be uncertain.
So, I think we should pick the secret option 4: Disallow metadata to be placed on nested-module definitions.
This isn't even my idea. Option 4 is what Rust and C++ do. For example, compiling this causes a syntax error:
namespace[[deprecated]] Foo::Bar::Baz
{
structHello { int i; };
}
/tmp/j2zpwYlh9a/main.cpp:4:1: error: a nested namespace definition cannot have attributes
4 | namespace [[deprecated]] Foo::Bar::Baz
| ^~~~~~~~~
But it's totally okay with attributes on 'normal' modules:
namespace[[deprecated]] Baz
{
structHello { int i; };
}
/tmp/f2wtwFCLHt/main.cpp: In function'intmain()':/tmp/f2wtwFCLHt/main.cpp:13:16: warning: 'Baz' is deprecated [-Wdeprecated-declarations] 13 | Baz::Hello there {5};
Since nested-module syntax is new for 3.8, we aren't loosing anything by not supporting this.
Of course, we can revisit this in the future if supporting metadata with nested-module syntax becomes a requested feature.
The text was updated successfully, but these errors were encountered:
For 3.8, we added support for nested module syntax:
This is great, but it introduces some unfortunate ambiguity with how metadata applies to this syntax.
For example, if you write:
I think there are really 3 separate ways to interpret this:
Bar
)Foo
)Foo::Bar
)I think all 3 of these are valid intuitive beliefs. So no matter which we pick, some users will be surprised, and all users will be uncertain.
So, I think we should pick the secret option 4: Disallow metadata to be placed on nested-module definitions.
This isn't even my idea. Option 4 is what Rust and C++ do. For example, compiling this causes a syntax error:
But it's totally okay with attributes on 'normal' modules:
Since nested-module syntax is new for 3.8, we aren't loosing anything by not supporting this.
Of course, we can revisit this in the future if supporting metadata with nested-module syntax becomes a requested feature.
The text was updated successfully, but these errors were encountered: