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

Alias any type is not working with named tuples #10982

Closed
SeanFeldman opened this issue Nov 17, 2024 · 2 comments
Closed

Alias any type is not working with named tuples #10982

SeanFeldman opened this issue Nov 17, 2024 · 2 comments

Comments

@SeanFeldman
Copy link

Issue Description

With C# 12, it's possible to alias any type. A project that has ImplicitUsings, it works using GlobalUsings.cs. Switching from GlobalUsings.cs to Directory.Build.props breaks compilation.

I've run into a situation where a named tuple alias with a nullable doesn't work, but a collection with elements of an identical named tuple does.

Steps to Reproduce

// GlobalUsings.cs
global using NamedTuple = (bool isUsed, string value);
global using NamedTupleList = System.Collections.Generic.List<(bool isUsed, string value)>;

// Anywhere in the project
NamedTuple nt;      // compiles
NamedTupleList ntl; // compiles

When attempting to use these aliases in all projects under solution using .csproj's Using element, NamedTuple doesn't work while NamedTupleList works.

The repro (link) is attempting to achieve this by defining the aliases in the Directory.Build.props file instead of GlobalUsing.cs in the following way.

<Project>
    <ItemGroup>
        <Using Include="(bool isUsed, string value)" Alias="NamedTuple" />
        <Using Include="System.Collections.Generic.List&lt;(bool isUsed, string value)&gt;" Alias="NamedTupleList" />
    </ItemGroup>
</Project>

With this change, the code fails.

// Anywhere in the project
NamedTuple nt;      // compiles
NamedTupleList ntl; // fails

Expected Behavior

NamedTuple and NamedTupleList types should be available and compilable.

Actual Behavior

NamedTupleList isn't available/compilable.

Analysis

No response

Versions & Configurations

MSBuild version 17.10.4+10fbfbf2e
.NET 8.0.300
OS Windows 10 Pro 22H2

@KalleOlaviNiemitalo
Copy link

Duplicate of dotnet/sdk#42479.

@SeanFeldman
Copy link
Author

Indeed. Closing in favour of dotnet/sdk#42479.

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

2 participants