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

GetAlternateLookup<ReadOnlySpan<char>>() does not work on FrozenSet<string> in .NET 9 RC 1 #107840

Closed
mfeemster opened this issue Sep 15, 2024 · 5 comments
Assignees
Milestone

Comments

@mfeemster
Copy link

mfeemster commented Sep 15, 2024

Description

I have installed .NET 9 RC 1 and have found that calling GetAlternateLookup<ReadOnlySpan<char>>() on FrozenSet<string> appears to not be supported. It gives an error of:

error CS9244: The type 'ReadOnlySpan' may not be a ref struct or a type parameter allowing ref structs in order to use it as parameter 'TAlternate' in the generic type or method 'FrozenSet.TryGetAlternateLookup(out FrozenSet.AlternateLookup)'

Reproduction Steps

var hs = new HashSet<string>()
{
	"str1",
	"str2",
	"str3",
}.ToFrozenSet(StringComparer.OrdinalIgnoreCase);
var alt = hs.GetAlternateLookup<ReadOnlySpan<char>>();//This line won't compile

Expected behavior

This should compile because the documentation says it's been added to FrozenSet.

https://learn.microsoft.com/en-us/dotnet/api/system.collections.frozen.frozenset-1.getalternatelookup?view=net-9.0

Actual behavior

The build fails with this error:

error CS9244: The type 'ReadOnlySpan' may not be a ref struct or a type parameter allowing ref structs in order to use it as parameter 'TAlternate' in the generic type or method 'FrozenSet.TryGetAlternateLookup(out FrozenSet.AlternateLookup)'

Regression?

No.

Known Workarounds

None.

Configuration

Visual Studio Community 2022 17.11.3
Windows 10
.NET 9 RC 1
<LangVersion>preview</LangVersion>

Other information

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Sep 15, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Sep 15, 2024
@svick
Copy link
Contributor

svick commented Sep 15, 2024

I believe the problem here is that the reference assembly version of FrozenSet<T> is missing where TAlternate : allows ref struct.

Compare:

public AlternateLookup<TAlternateKey> GetAlternateLookup<TAlternateKey>() where TAlternateKey : notnull, allows ref struct

public System.Collections.Frozen.FrozenDictionary<TKey,TValue>.AlternateLookup<TAlternateKey> GetAlternateLookup<TAlternateKey>() where TAlternateKey : notnull, allows ref struct { throw null; }

public AlternateLookup<TAlternate> GetAlternateLookup<TAlternate>() where TAlternate : allows ref struct

public System.Collections.Frozen.FrozenSet<T>.AlternateLookup<TAlternate> GetAlternateLookup<TAlternate>() { throw null; }

@mfeemster
Copy link
Author

This sounds correct. Do you know of a workaround? Or can it only be fixed when the next RC is released?

@martincostello martincostello added area-System.Collections and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Sep 15, 2024
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-collections
See info in area-owners.md if you want to be subscribed.

@stephentoub stephentoub self-assigned this Sep 15, 2024
@stephentoub stephentoub added this to the 9.0.0 milestone Sep 15, 2024
@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Sep 15, 2024
@stephentoub
Copy link
Member

Thank you for reporting this.

Do you know of a workaround? Or can it only be fixed when the next RC is released?

A hack would be to reference the implementation assembly rather than the ref assembly.

The only real fix is to fix the ref assembly, though.

#107846
#107847

@jeffhandley
Copy link
Member

Fixed by #107846

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

No branches or pull requests

5 participants