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

Wrong nullable value type expression decompilation #2288

Closed
wwh1004 opened this issue Jan 30, 2021 · 1 comment
Closed

Wrong nullable value type expression decompilation #2288

wwh1004 opened this issue Jan 30, 2021 · 1 comment
Labels
Bug Decompiler The decompiler engine itself

Comments

@wwh1004
Copy link
Contributor

wwh1004 commented Jan 30, 2021

input:

Guid? a = null;
Guid? b = null;
var expr = (Expression<Func<bool>>)(() => a == b);

ilspy output:

Guid? a = null;
Guid? b = null;
Expression<Func<bool>> expr = () => (Guid)a == (Guid)b;

they are different semantic

stloc expression(ILFunction.ET[System.Linq.Expressions.Expression`1[[System.Func`1[[System.Boolean]]]]] {
	
	BlockContainer {
		Block IL_0000 (incoming: 1) {
			leave IL_0000 (call op_Equality(ldloc a, ldloc b))
		}

	}
}
)
stloc expression2(ILFunction.ET[System.Linq.Expressions.Expression`1[[System.Func`1[[System.Boolean]]]]] {
	
	BlockContainer {
		Block IL_0000 (incoming: 1) {
			leave IL_0000 (call op_Equality(expression.tree.cast System.Guid(ldloc a), expression.tree.cast System.Guid(ldloc b)))
		}

	}
}
)

but ilspy will decompile them to the same code

Expression<Func<bool>> expr = () => (Guid)a == (Guid)b;
Expression<Func<bool>> expr2 = () => (Guid)a == (Guid)b;

ilspy version: 7.0.0.6306-preview2

@wwh1004 wwh1004 added Bug Decompiler The decompiler engine itself labels Jan 30, 2021
@wwh1004
Copy link
Contributor Author

wwh1004 commented Jan 30, 2021

https://docs.microsoft.com/en-us/dotnet/api/system.linq.expressions.binaryexpression.isliftedtonull?view=net-5.0
liftToNull is different with lift
liftToNull means return value is also nullable

if (isLifted != 0)
{
method = CSharpOperators.LiftUserDefinedOperator((IMethod)method);
}
return (() => new Call((IMethod)method) { Arguments = { left(), right() } }, method.ReturnType);

i think this should be updated

wwh1004 added a commit to wwh1004/ILSpy that referenced this issue Jan 30, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Decompiler The decompiler engine itself
Projects
None yet
Development

No branches or pull requests

1 participant