is it bug?

drug drug2004 at bk.ru
Tue Sep 26 07:13:40 UTC 2017


25.09.2017 22:58, Steven Schveighoffer пишет:
> 
> First up, the non-bug:
> 
> You wrote:
> 
> writeln(bar.foo.isNull); // false
> writeln(bar.foo); // error
> 
> But bar.foo is this:
> 
> struct Foo
> {
>     Nullable!(char[2]) value;
> }
> 
> And bar.foo is nullable itself. It's a nullable!Foo.
> 
> It's a Nullable!Foo, that is not null, but contains a Nullable!(char[2]) 
> that *is* null.
> 
> So when you print Foo, it calls the get on it, which works, and then 
> tries to print all its members (the default thing for std.format), and 
> when it gets to the *value* member, it crashes.

so the bug here is that instead of outputting "null" it tries to get 
null value, isn't it? And I guess that std.format process char-based 
types in different manner than others so we have working int, float etc 
arrays and failing char-based types (string, wstring, char[], static 
char[] and so on)

> 
> So bar.foo.isNull has no bearing on the actual error. 
> bar.foo.value.isNull is true, and there's where the error happens.
> 
> Your first example was more confusing because it wasn't named `value`, 
> it was named `foo`!
> 
> Second is the actual bug, and we don't need Bar to show it:
> 
> Foo foo;
> writeln(foo.value); // Nullable.null
> writeln(foo); // error
> 
> There is something different that happens when you try to print a 
> Nullable directly, than when you print a struct containing the Nullable.
> 
> So this is the reduced case. The second line should print 
> Foo(Nullable.null), not throw an error. And yes, it has something to do 
> with the fact that it's a char[2]. int works. char[] also fails.
> 
> -Steve



More information about the Digitalmars-d-learn mailing list