www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - what's the proper way to assign this?

reply Dr Machine Code <jckj33 gmail.com> writes:
I've tried to build 2 years old D project and I was getting the 
error:

  > Error: cannot append type `Nullable!(SelectorEntry)` to type 
`SelectorEntry[]`

I went to use Nullable, 'cause I've never used it before. Boiling 
down the error was something like (minimal code reproduction):

```d
    	auto e = Entry("Bill", 30);
    	auto entry = nullable(e);
	Entries data;
	data.entries ~= entry;


struct Entry
{
	string name;
	int id;
}

struct Entries
{
	Entry[] entries;
	int lid;
}
```

I could fix just with

```d
	data.entries ~= entry.get;
```

taking away all the nullables. My question is: should I use .get 
directly or there's a "proper way" to do it, maybe keeping the 
nullable? I'm asking so I don't create a misbehavior in the 
application.
Jan 04 2022
parent reply Adam D Ruppe <destructionator gmail.com> writes:
On Tuesday, 4 January 2022 at 17:23:11 UTC, Dr Machine Code wrote:
 I could fix just with

 ```d
 	data.entries ~= entry.get;
 ```
This is what the original code was doing - it used to implicitly do this. So while this might be buggy, it wouldn't be a new bug at least.
Jan 04 2022
parent reply Dr Machine Code <jckj33 gmail.com> writes:
On Tuesday, 4 January 2022 at 17:58:05 UTC, Adam D Ruppe wrote:
 On Tuesday, 4 January 2022 at 17:23:11 UTC, Dr Machine Code 
 wrote:
 I could fix just with

 ```d
 	data.entries ~= entry.get;
 ```
This is what the original code was doing - it used to implicitly do this. So while this might be buggy, it wouldn't be a new bug at least.
it's supposed to call .get implicitly then right? what made that change, assuming it worked at time. Library? compile changes?
Jan 04 2022
parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 1/4/22 10:53 AM, Dr Machine Code wrote:
 what made that change, 
 assuming it worked at time. Library? compile changes?
Here is the changelog item: https://dlang.org/changelog/2.088.0.html#remove-nullable-alias-get-this A reminder at least to myself: I found it by searching for Nullable in the search field. I didn't know Change Log could be searched separately. Cool! :) Ali
Jan 04 2022
parent Dr Machine Code <jckj33 gmail.com> writes:
On Tuesday, 4 January 2022 at 19:06:52 UTC, Ali Çehreli wrote:
 On 1/4/22 10:53 AM, Dr Machine Code wrote:
 what made that change, assuming it worked at time. Library? 
 compile changes?
Here is the changelog item: https://dlang.org/changelog/2.088.0.html#remove-nullable-alias-get-this A reminder at least to myself: I found it by searching for Nullable in the search field. I didn't know Change Log could be searched separately. Cool! :) Ali
a reminder to myself is check the change log first lol thanks for the link
Jan 04 2022