-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Generated code for Expression-tree instantiation crashes when it refers to ValueTuple<A,B>.Equals #27322
Comments
Perhaps helpful too are two decompiles, one using ValueTuple, and one using something similar, highlighting the difference in generated code: Decompiles of a broken scenario and a working one:
(Corresponding to the following linqpad snippet:) void Main()
{
var tupleA = (1, 3);
var myTupleA = ToMyValueTuple(tupleA);
tupleA.Dump();
Expression<Func<bool>> ok = () => myTupleA.Equals(myTupleA);//no crash
ok.Dump();
Expression<Func<bool>> err21 = () => tupleA.Equals(tupleA);//crash
err21.Dump();
}
static MyValueTuple<T1, T2> ToMyValueTuple<T1, T2>((T1, T2) tuple) => new MyValueTuple<T1, T2>(tuple);
public struct MyValueTuple<T1, T2> : IEquatable<MyValueTuple<T1, T2>> {
public readonly T1 v1;
public readonly T2 v2;
public MyValueTuple((T1 v1, T2 v2) tuple) => (v1, v2) = tuple;
public bool Equals(MyValueTuple<T1, T2> other) => Equals(v1, other.v1) && Equals(v2, other.v2);
} In short, it's calling the wrong overload of GetMethodFromHandle (the one for non-generic handles, instead of the one for a method handle with a generic type handle). |
This is likely a symptom of #20648 |
Fixes dotnet#27322 (C# only) VB fix depends on dotnet#20648
@AlekseyTs wrote in #43518 (review)It doesn't look like VB fix really depends on #20648. There is a safe and simple fix that we can make in
Please add the fix and the following test:
|
Version Used: Various, including VS15.7.3 and VS15.8.0 preview2
Steps to Reproduce:
Expected Behavior:
The code runs without throwing.
Actual Behavior:
The above snippet crashes at line
crash 1
withSystem.ArgumentException : Cannot resolve method Boolean Equals(System.ValueTuple`2[System.Int32,System.Int32]) because the declaring type of the method handle System.ValueTuple`2[T1,T2] is generic. Explicitly provide the declaring type to GetMethodFromHandle.
If you remove that line, it crashes at line
crash 2
withSystem.ArgumentException : Cannot resolve method Int32 CompareTo(System.ValueTuple`2[System.Int32,System.Int32]) because the declaring type of the method handle System.ValueTuple`2[T1,T2] is generic. Explicitly provide the declaring type to GetMethodFromHandle.
Note (from @gafter):
This bug has been confirmed fixed in C# (#43518), but not in VB. See discussion below.
The text was updated successfully, but these errors were encountered: