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

Allow pointer types and C# aliases in using aliases #2325

Closed
john-h-k opened this issue Mar 10, 2019 · 7 comments
Closed

Allow pointer types and C# aliases in using aliases #2325

john-h-k opened this issue Mar 10, 2019 · 7 comments

Comments

@john-h-k
Copy link

Currently this code won't compile:

using LPCSTR = char*;

Neither is the fully qualified name

using LPCSTR = System.Char*;

It would be useful to be able to alias pointer types like this, and alias C# aliases, such as

using nuint = ulong

rather than

using nuint = System.UInt64;

The use case at the moment for me is when porting across Win32 methods and structs. I can blindly set all of these to System.IntPtr but it is clunky and, importantly, is functionally different, as it is (less) type safe and requires a cast before it can be used as desired (e.g, accessing a member).

This is purely compile time logic and as such doesn't seem complex to add, but would be nice for more fully fledged using aliases and for making interop just slightly easier

@YairHalberstadt
Copy link
Contributor

YairHalberstadt commented Mar 10, 2019

I can't imagine this would be at all difficult to add: if anything I imagine there's custom logic in the compiler that forbids it which would have to be removed.

I think the real issue is whether the benefits are strong enough to be worth the effort for the LDM to make the change. It's a rather niche use case.

However I think there have been other issues about being able to use type aliases for tuples, as well as for open Generics. There's also been discussion around allowing a type alias to be used globally rather than locally.

So perhaps the LDM could take a fresh look at aliases altogether at some point. I imagine they will be connected to roles in some way.

Here are the links to other issues around aliases:

#1239
#423
#259
#1659
#90

@john-h-k
Copy link
Author

Yeah, I justified it given the fact it is purely compile time, not a breaking change, and simple. I definitely understand it's quite a niche change, but given a general rework of aliases it would definitely be nice. Thanks for the link

@ghost
Copy link

ghost commented Dec 15, 2020

using unsafe LPCSTR* = char*;

I think all pointer types must need * and unsafe

Function pointers

using unsafe Action* = delegate*<void>

@Rekkonnect
Copy link
Contributor

Rekkonnect commented Sep 19, 2021

The spec specifically mentions that pointers and language keyword aliases become valid expressions in using alias declarations. This issue may be therefore closed.

@Joe4evr
Copy link
Contributor

Joe4evr commented Sep 19, 2021

@alfasgd Issues here don't get closed until the change is written in the ECMA spec.
See also the label: Implemented Needs ECMA Spec.

@Rekkonnect
Copy link
Contributor

Though #4284 tracks the same feature implementation, and this issue covers a narrower spectrum of the implemented feature, is it fine to have two issues open at the same time like that? Besides, this issue is not even labeled.

@333fred 333fred closed this as completed Sep 19, 2021
@333fred
Copy link
Member

333fred commented Sep 19, 2021

Nope. Duplicates should be closed, thanks.

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

No branches or pull requests

5 participants