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

GenAPI produces where T : ValueType given ref T return with no type constraint #6719

Open
2 tasks
dagood opened this issue Dec 22, 2020 · 1 comment
Open
2 tasks
Labels
area-Infrastructure-libraries Area maintained by .NET libraries team: APICompat, AsmDiff, GenAPI, GenFacades, PkgProj, etc help wanted

Comments

@dagood
Copy link
Member

dagood commented Dec 22, 2020

  • This issue is blocking
  • This issue is causing unreasonable pain

GenAPI 1.0.0-beta.18619.2

In https://www.nuget.org/packages/System.Runtime.CompilerServices.Unsafe/5.0.0 lib/netcoreapp2.0/System.Runtime.CompilerServices.Unsafe.dll, we have this method (output from ILSpy):

// System.Runtime.CompilerServices.Unsafe
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref T Unbox<T>(object box)
{
	return ref (T)box;
}
.method public hidebysig static 
	!!T& Unbox<([System.Runtime]System.ValueType) T> (
		object 'box'
	) cil managed aggressiveinlining 
{
	.param constraint T, [System.Runtime]System.ValueType
		.custom instance void System.Runtime.Versioning.NonVersionableAttribute::.ctor() = (
			01 00 00 00
		)
	// Method begins at RVA 0x22b4
	// Code size 7 (0x7)
	.maxstack 1

	IL_0000: ldarg.0
	IL_0001: unbox !!T
	IL_0006: ret
} // end of method Unsafe::Unbox

GenAPI gives me this:

public static ref T Unbox<T>(object box) where T : System.ValueType { throw null; }
// ^ error CS0702: Constraint cannot be special class 'ValueType' 

In the package's ref/netstandard2.0/[...].dll, this API is actually generated like this:

// System.Runtime.CompilerServices.Unsafe
public static ref T Unbox<T>(object box) where T : struct
{
	throw null;
}

/cc @safern

@dagood
Copy link
Member Author

dagood commented Dec 22, 2020

Interesting that ilasm had a similar bug: dotnet/runtime#45183. Might not be any meaningful connection though.

@ericstj ericstj added the area-Infrastructure-libraries Area maintained by .NET libraries team: APICompat, AsmDiff, GenAPI, GenFacades, PkgProj, etc label Mar 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Infrastructure-libraries Area maintained by .NET libraries team: APICompat, AsmDiff, GenAPI, GenFacades, PkgProj, etc help wanted
Projects
None yet
Development

No branches or pull requests

3 participants