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

Compiler erroneously allows pointer to be used within a type-argument in a using-alias #67281

Closed
CyrusNajmabadi opened this issue Mar 13, 2023 · 1 comment · Fixed by #67282
Closed
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@CyrusNajmabadi
Copy link
Member

This is currently allowed in the language without error:

using X = List<int*[]>;

This is due to the compiler only checking directly that the type parameters of a generic type are managed types, and 'Arrays' are managed types.

However, this should likely be illegal as the spec defines the concept of an Unsafe Context, which is the only location where pointers can even be syntactically used.

We need to decide what to do about this. Given that the above code was allowed since C#2.0 there is a def compat concern if we were to disallow this.

That said, in C# 12 we added the ability to say using unsafe X = .... This gives us the option to say that in C# 12 we would now make this required, but continue to allow it in C#11 and prior. We could potentially also have our upgrade-fixers detect/fix this in the rare, but possible, chance that this comes up in the wild.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Mar 13, 2023
@CyrusNajmabadi CyrusNajmabadi changed the title Compiler allows pointer to be used in using-alias Compiler erroneously allows pointer to be used within a type-argument in a using-alias Mar 13, 2023
@333fred
Copy link
Member

333fred commented Mar 14, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
2 participants