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

False errors for maybe operator/optional chain #544

Closed
Lexikos opened this issue Jun 29, 2024 · 0 comments
Closed

False errors for maybe operator/optional chain #544

Lexikos opened this issue Jun 29, 2024 · 0 comments

Comments

@Lexikos
Copy link

Lexikos commented Jun 29, 2024

a := {123:IsObject, 222:{__item:42}}
assert (a?.123) ?? 0 = IsObject
; this?.1 can be member access, but in this case is ternary,
; because a?.123() is always member access:
assert (this?.1 && a?.123() : 0) ?? 0
assert ((this?.1 && a?.222[] : 0) ?? 0) = 42

f() => 42
assert f.%unset%() = 42
assert f.%a?%() = 42
a := 'Bind'
assert f.%a?%() is BoundFunc

assert(c) => c ; (Not the actual definition)

This is taken from some test units. With v2.4.6, there are some incorrect "Missing ':'" diagnostics:

  • (a?.123). This should be interpreted as member access like a.123, because it can't be ternary. I think the exact rule isn't documented, but basically it just tries to make the new syntax work without breaking any scripts (so ternary takes precedence).
  • this?.1. The comment explains, but I forget how it actually works, so feel free to ignore these two.
  • f.%a?%. This just allows a to be unset; "unset resolves to the default property (either __Item or Call)."

I think that it would be safe for the extension to assume ?. is member access if the colon is missing, although the actual interpretation might differ in some complicated cases.

@thqby thqby closed this as completed in 1739c68 Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant