using alias = any_type
. roslyn#50167Simply put,
using T = System.Collections.Generic.List<(string, int)>;
is legal. While
is not. I suspect this was simply an oversight, but either way there seems no good reason that it shouldn't work (and it parses terribly and does not produce a good error message either).
MotivationLanguage consistency, completing things we started. Without this syntax you cannot give tuple names either, which is a big downside.
Language ChangeThe grammar will be changed like so:
using_alias_directive - : 'using' identifier '=' namespace_or_type_name ';' + : 'using' 'unsafe'? identifier '=' namespace_or_type';' ;Concluded Questions
Similarly, what are the semantics of a pointer type in an alias. e.g. using XPtr = X*;
. Using aliases are in a location that generally cannot be marked unsafe
. So we'd likely want this to be legal, with an error if you then use XPtr in an safe context.
Answer:
Aliases to pointers are allowed. However, they must be written in the form using unsafe X = T*;
unsafe
will be an error.using unsafe X = T*;
is written and T
is not a type that is valid to take a pointer to. Regardless if 'X' is not referenced anywhere in the code.using unsafe X = T*;
would be ok, but the user has not passed the /unsafe
flag to the compiler.What are the semantics of a NRT nullable type with an alias. e.g. using X = string?;
. Specifically, does the alias have to be an a #nullable enable
region? Or can it be located anywhere. Then, what does it mean if that alias is used in a context that doesn't allow nullable? Is that an error, a warning, or is the nullable annotation silently ignored?
Answer:
using X = string?;
is not legal.using X = List<string?>;
remains legal as there is no top-level NRT, just an interior NRT.using X = int?;
remains legal as this is a top-level value type, not a reference type.For unsafe code, should the syntax be using unsafe X = int*;
or unsafe using X = int*;
. i.e. does the unsafe
modifier come before or after the using
keyword.
Answer (LDM meeting 2/1/23):
using unsafe ...
. This keeps using
blocks consistent with using
always being the first token.https://github.com/dotnet/csharplang/blob/main/meetings/2021/LDM-2021-09-20.md#type-alias-improvements
https://github.com/dotnet/csharplang/blob/main/meetings/2022/LDM-2022-08-31.md#using-aliases-for-any-type
https://github.com/dotnet/csharplang/blob/main/meetings/2022/LDM-2022-09-28.md#ungrouped
https://github.com/dotnet/csharplang/blob/main/meetings/2023/LDM-2023-01-11.md#using-aliases-for-any-types
yaakov-h, CyrusNajmabadi, omariom, kyoyama-kazusa, pinkfloydx33 and 110 moreVisualMelondasMulli, laicasaane, SommerEngineering, EduardoLarios, daiplusplus and 2 moredaiplusplus and haltcaseSupinePandora43
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4