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
recursive automatic deference (
ptr ptr... T
orref ref... T
orptr 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 aref T
orptr T
also cases like
ptr ptr T
orptr ref T
, etc. are less commonExample
Actual Output
Expected Output
An error indicating automatic dereferencing for object attribute access is only for
ptr T
andref T
and not recursiveReferences
C operator
->
marks error for apointer of pointer of a struct
and is valid only forpointer of a struct