DerivcoIpswich / dsharp

A fork of the Script# project.
http://www.derivco.co.uk
Other
20 stars 13 forks source link

Calling Equals from GetValueOrDefault in Nullable Types transpiles incorrectly to non-existing function #250

Open charlisi opened 4 years ago

charlisi commented 4 years ago

I guess this happens when the nullable instance is null (undefined) due to GetValueOrDefaut being transpiled to || 0. Here is an example with Nullable, where all 2 fields are of this type:

private bool Predicate(AModel model)
        {
            return !ANullableDateTime.GetValueOrDefault().Equals(model.ANullableDateTime.GetValueOrDefault()));
        }

This gets transpiled as in 1.8.1:

_predicate$6: function(model) {
      return !(this.ANullableDateTime || 0).equals((model.ANullableDateTime || 0));
    }

Yielding the runtime error in the console: (this.ANullableDateTime || 0).equals is not a function

charlisi commented 4 years ago

Here's a sample project DSharpTestConsoleApp1.zip