Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mrgaturus opened this issue Sep 16, 2024 · 1 comment
Labels
compiler/sem Related to semantic-analysis system of the compiler language-design Language design syntax, semantics, types, statics and dynamics.

Comments

@mrgaturus
Copy link
Contributor

mrgaturus commented Sep 16, 2024

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

@alaviss alaviss added the compiler/sem Related to semantic-analysis system of the compiler label Sep 16, 2024
@saem
Copy link
Collaborator

saem commented Sep 16, 2024

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

@zerbina zerbina added the language-design Language design syntax, semantics, types, statics and dynamics. label Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/sem Related to semantic-analysis system of the compiler language-design Language design syntax, semantics, types, statics and dynamics.
Projects
None yet
Development

No branches or pull requests

4 participants