NonNull template
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Sat Apr 19 06:41:07 UTC 2025
On 19/04/2025 6:11 PM, Walter Bright wrote:
> On 4/17/2025 7:48 PM, Richard (Rikki) Andrew Cattermole wrote:
>> ```d
>> void main() {
>> func(new int); // ok
>> func(null); // error
>> }
>>
>> void func(int* ptr) {
>> int v = *ptr;
>> }
>> ```
>
> It always looks simple in such examples, but then there are things like:
>
> ```d
> struct S { int a,b; int* p; }
>
> void main()
> {
> S s;
> funky(&s);
> func(s.p);
> }
> ```
> where trying to track information in structs gets complicated fast.
Yeah indirection.
It is not a solved problem, even if you throw the type system with say a
type qualifier into the mix.
https://kotlinlang.org/docs/java-to-kotlin-nullability-guide.html
"Tracking multiple levels of annotations for pointers pointing to
pointers would make the checker more complicated, because this way a
vector of nullability qualifiers would be needed to be tracked for each
symbol. This is not a big caveat, since once the top level pointer is
dereferenced, the symvol for the inner pointer will have the nullability
information. The lack of multi level annotation tracking only
observable, when multiple levels of pointers are passed to a function
which has a parameter with multiple levels of annotations. So for now
the checker support the top level nullability qualifiers only.:
int * __nonnull * __nullable p;
int ** q = p;
takesStarNullableStarNullable(q);"
https://clang.llvm.org/docs/analyzer/developer-docs/nullability.html
Its actually a pretty good example of why I think supporting modelling
of fields is not worth our time. Plus throw in multi-threading and boom
shuckala, not modellable anymore.
More information about the Digitalmars-d
mailing list