Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create using-alias-types.md #5174

Merged
merged 3 commits into from
Sep 24, 2021
Merged

Create using-alias-types.md #5174

merged 3 commits into from
Sep 24, 2021

Conversation

CyrusNajmabadi
Copy link
Member

No description provided.

```
using_alias_directive
- : 'using' identifier '=' namespace_or_type_name ';'
+ : 'using' identifier '=' (namespace_name | type) ';'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does type include top-level nullability annotation?
I assume this allows built-in types using Id = int;. Is that right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does type include top-level nullability annotation?

Yes. It would.

I assume this allows built-in types using Id = int;. Is that right?

yes, it would.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It would [include top-level nullability annotation].

From our offline discussion, this raises a question for how the three annotations (?, ! and ~/oblivious) interact in the declaration versus the use-site. For example, what happens if you put ? in the declaration and the use-site?

@cston
Copy link
Member

cston commented Sep 10, 2021

See also #4452.

@jcouv jcouv self-assigned this Sep 10, 2021
@jcouv jcouv requested a review from a team September 10, 2021 19:38
@CyrusNajmabadi
Copy link
Member Author

See also #4452.

This is very intentionally not trying to support the case of using X<T> = ... While i think that is valuable for us to look into, it's orthogonal and much larger in scope (esp. on the impl side). Whereas the above proposal is actually quite trivial to support and hits a lot of pain cases we have today.

Copy link
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spec looks good to me. Do we have a championed issue?

@tannergooding
Copy link
Member

@CyrusNajmabadi, would this also work for other aliases?

That is, could I do the following?

using HANDLE = void*;
using HWND = HANDLE;

I was wanting to add a feature to the ClangSharp P/Invoke generator that generates global using directives for typedefs and I've found the following three issues that are blocking:

  • Can't use keywords, which is particularly relevant since nint and IntPtr behave differently
  • Can't use pointers (important for typedefs to pointers)
  • Can't use other defined aliases (important for typedefs to typedefs)

@CyrusNajmabadi
Copy link
Member Author

That is, could I do the following?

using HANDLE = void*;
using HWND = HANDLE;

The first is completely allowed. The second would not be allowed as a using directive cannot reference another using directive in the same block. However, this is ok:

using HANDLE = void*;
namespace X
{
  using HWND = HANDLE;
}

or

using HANDLE = void*;
using HWND = void*;

Can't use keywords, which is particularly relevant since nint and IntPtr behave differently

Keywords would be fine.

Can't use pointers (important for typedefs to pointers)

You will be able to use pointers.

Can't use other defined aliases (important for typedefs to typedefs)

If in the same scope this will continue to not work and you'll still have to explicitly write out the entire type signature again.

@tannergooding
Copy link
Member

Keywords would be fine.
You will be able to use pointers.

Awesome.

If in the same scope this will continue to not work and you'll still have to explicitly write out the entire type signature again.

This is a bit unfortunate but also not overly complex to handle, thankfully.

@CyrusNajmabadi
Copy link
Member Author

This is a bit unfortunate but also not overly complex to handle, thankfully.

Understood. Note that i'm not opposed to work here. But i would consider it more of a separate feature.

@tannergooding
Copy link
Member

Yep definitely understand.

Its basically just traversing the typedefs to the "concrete" type for ClangSharp, I expect its a bit more complex for Roslyn to handle 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

5 participants