Cleared AA == and is have different results. Why?

Nick Treleaven nick at geany.org
Wed Sep 10 14:38:44 UTC 2025


On Wednesday, 10 September 2025 at 14:01:29 UTC, Brother Bill 
wrote:
> Page 119 of Programming in D
>
> It seems odd that == null and is null have different values?
> Is this a bug or feature?
> If a feature, what is the meanings of == null vs. is null?

Feature. An AA has reference semantics. Removing all elements 
does not set it to `null` (the `.init` value), because it is 
already allocated, which may be useful for future operations.

Comparing for equality against null is true because both AA 
references have no elements (null is a valid AA reference).

Comparing for identity is false because `null` has no AA 
allocation whereas `dayNumbers` does - it isn't null.

https://dlang.org/spec/hash-map.html#construction_and_ref_semantic


More information about the Digitalmars-d-learn mailing list