netcoredbg icon indicating copy to clipboard operation
netcoredbg copied to clipboard

The value of type double? property in class is confusing

Open fenixjiang opened this issue 2 years ago • 4 comments

For type int?, double?, string?... I decide whether to display null directly based on HasValue value. But while they are properties of a class, and not assigned a vlaue. the value is like this:

ncdb> p variables.DoubleValue ariables.DoubleValue = { System.Nullable<double>} : {hasValue=false, value =0, HasValue = true, Value = 0}

The hasValue and HasValue are different!! the values ​​are consistent while int?, double?... is a local variables.

Below is my test code (simplified):

internal class Variables { public double? DoubleValue{get;set;} }

static void Main(string[] args) { var variables = new variables(); //breakpoint here, check values }

Another problem about double? when assigned a value to double? property, it's value like this: ncdb> p variables.DoubleValue ariables.DoubleValue = { System.Nullable<double>} : {hasValue=true, value =36.5, HasValue = true, Value = 4.940656458412465e-324}

In my opinion,these two problems is bugs , I tried to debug and fix them, but failed. The calculation part is not fully understood yet.

So. Are the above bugs? If they are indeed correct, I want to directly display the null value ​​and show the actual value,what should I do?

fenixjiang avatar Jan 25 '24 06:01 fenixjiang

https://github.com/dotnet/runtime/blob/135fec006e727a31763271984cd712f1659ccbd3/src/libraries/System.Private.CoreLib/src/System/Nullable.cs#L21-L75 Looks like fields was not initialized by constructor before real code execution during evaluation (properties getters calls). Is this case provide same issues:

internal class Variables { public double? DoubleValue{get;set;} }

static void Main(string[] args) { var variables = new variables();  
;//breakpoint here, check values } 

?

viewizard avatar Jan 25 '24 08:01 viewizard

@viewizard Yes, that case provide same issues.

fenixjiang avatar Jan 25 '24 09:01 fenixjiang

Hmm... strange, because HasValue code is https://github.com/dotnet/runtime/blob/135fec006e727a31763271984cd712f1659ccbd3/src/libraries/System.Private.CoreLib/src/System/Nullable.cs#L33-L37

        public readonly bool HasValue
        {
            [NonVersionable]
            get => hasValue;
        }

and hasValue=false, HasValue = true could happens only in case https://github.com/dotnet/runtime/blob/135fec006e727a31763271984cd712f1659ccbd3/src/libraries/System.Private.CoreLib/src/System/Nullable.cs#L27-L31

        public Nullable(T value)
        {
            this.value = value;
            hasValue = true;
        }

not called first (before getter call) and hasValue have default (false) value.

~~Could you please provide full code (with DoubleValue property initialization) you are using for testing?~~

If they are indeed correct, I want to directly display the null value ​​and show the actual value,what should I do?

We don't support System.Nullable<> for now, so you could see only internal members (instead of "real" value).

viewizard avatar Jan 25 '24 09:01 viewizard

Hmm... looks like works different for public double? DoubleValue; and public double? DoubleValue{get;set;}. Will add this in investigation list.

viewizard avatar Jan 25 '24 10:01 viewizard