question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invalid code when decompiling simple F# not (isNull x) into C#

See original GitHub issue

Consider this simple code:

open System

type C() =
    member __.notNull x = not (isNull x)

(see https://sharplab.io/#v2:DYLgZgzgPg9gDgUwHYAIDKBPCAXBBbAWAChjsNEUBhACgEoUBeYlFlPfAIwQCcUB9PgDokMbADkArsGAoAHoxQjsKagEsIk6XNpA)

It decompiles into that:

using Microsoft.FSharp.Core;
using System;
using System.Reflection;
[assembly: AssemblyVersion("0.0.0.0")]
[assembly: FSharpInterfaceDataVersion(2, 0, 0)]
[CompilationMapping(SourceConstructFlags.Module)]
public static class _
{
    [CompilationMapping(SourceConstructFlags.ObjectType)]
    [Serializable]
    public class C
    {
        public C() : this()
        {
        }
        public bool notNull<a>(a x) where a : class
        {
            return x == null ? 1 : 0 == 0;
        }
    }
}
namespace <StartupCode$_>
{
    internal static class $_
    {
    }
}

That statement return x == null ? 1 : 0 == 0 is very strange because it doesn’t compile in C#.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ashmindcommented, May 30, 2017

@ForNeVeR Thanks for reporting! The decompilation is currently handled by an external component (ILSpy). The version I’m using is somewhat outdated – I’ll try updating to latest sometime later and I’ll let you know if they’ve fixed it.

0reactions
ForNeVeRcommented, Jun 25, 2017

Thanks for the fix and for the clarification. I’ve updated the ILSpy issue and reclassified it as an enhancement.

(Also I can confirm that the issue has been fixed.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Apktool and dummy values (once for all) · Issue #2104
I: Using Apktool 2.3.2 W: Could not find sources I: Checking ... I try to decompile) is from a ROM (Evolution X 2.0)...
Read more >
If Not IsNull in ASP Classic
To fix the code remove the = from the <% %> tags, like so; <% If Not IsNull(rs("ContractValue")) Then Response.
Read more >
ISNULL formula not behaving as expected
I've tried testing with other null currency values and it still seems to be not working. IF(ISNULL(field__c), 1, 0). formula.
Read more >
What does it mean to do a "null check" in C or C++?
Null checks (and other forms of Defensive Programming) clutter code up, and actually make it more error prone than other error-handling ...
Read more >
What's New in EF Core 7.0
Improved SQL for simple Identity insert. The case above inserts a single row with an IDENTITY key column and no other database-generated values....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found