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

comparing variable of type parameter against null generates wrong code. #242

Open
adrianoc opened this issue Jul 4, 2023 · 0 comments
Open
Labels
🐛 bug Something isn't working
Milestone

Comments

@adrianoc
Copy link
Owner

adrianoc commented Jul 4, 2023

using System;
class C
{
    bool Test<T>(T value) => value != null;
}

generates a call to Object.op_Inequality()

//Parameters of 'bool Test<T>(T value) => value != null;'
var p_value_4 = new ParameterDefinition("value", ParameterAttributes.None, gp_T_2);
md_Test_1.Parameters.Add(p_value_4);
il_Test_3.Emit(OpCodes.Ldarg_1);
il_Test_3.Emit(OpCodes.Ldnull);
il_Test_3.Emit(OpCodes.Call, assembly.MainModule.ImportReference(TypeHelpers.ResolveMethod(typeof(System.Object), "op_Inequality",System.Reflection.BindingFlags.Default|System.Reflection.BindingFlags.Static|System.Reflection.BindingFlags.Public, "System.Object", "System.Object")));
il_Test_3.Emit(OpCodes.Ret);

instead of something like:

https://cutt.ly/IwuPByZ1

        IL_0000: ldarg.1
        IL_0001: box !!T
        IL_0006: ldnull
        IL_0007: cgt.un
        IL_0009: ret
@adrianoc adrianoc added the 🐛 bug Something isn't working label Jul 4, 2023
adrianoc added a commit that referenced this issue Jul 4, 2023
adrianoc added a commit that referenced this issue Jul 22, 2023
@adrianoc adrianoc reopened this Nov 27, 2024
@adrianoc adrianoc modified the milestones: Future, 2.19 Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant