nim-works / nimskull

An in development statically typed systems programming language; with sustainability at its core. We, the community of users, maintain it.
https://nim-works.github.io/nimskull/index.html
Other
272 stars 38 forks source link

recursive automatic deference for object attribute access may be misleading #1461

Open mrgaturus opened 6 days ago

mrgaturus commented 6 days ago

recursive automatic deference (ptr ptr... T or ref ref... T or ptr ref... T, etc) for object attribute access may be misleading due two reasons: 1) user is not aware how many dereferences occurs for object attribute access 2) user is not aware if is having a pointer of pointer due type aliases naming a ref T or ptr T

also cases like ptr ptr T or ptr ref T, etc. are less common

Example

type
  MyObject = object
    a, b: int

var x = MyObject(a: 10, b: 20)
let p = addr x # ptr T
let pp = addr p # ptr ptr T
let ppp = addr pp # ptr ptr ptr T

echo p.a # ptr T is allowed have automatic dereference
         # to access object atributes

# this automatic deference should be an error
# for ptr ptr... T
echo pp.a
echo ppp.a

# user should dereference first until get a ptr T
echo pp[].a
echo ppp[][].a

Actual Output

10
10
10
10
10

Expected Output

An error indicating automatic dereferencing for object attribute access is only for ptr T and ref T and not recursive

References

C operator -> marks error for a pointer of pointer of a struct and is valid only for pointer of a struct

saem commented 5 days ago

This is a "feature" now we need to decide if we want this or not.