-
-
Notifications
You must be signed in to change notification settings - Fork 48
Add warning for lvalue indexing inconsistency. #1059
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
Conversation
| name | ||
| | LValueMultiIndexing -> | ||
| Fmt.pf ppf | ||
| "Left hand side of an assignment cannot have nested multi-indexing." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More of a question than anything - after removal do you think we should change the parser/AST to enforce this, or keep it in typechecking?
Is the eventual hope to re-introduce with matching semantics?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know. Cleaning up the AST seems like a good idea but nested indexing is still allowed when all the indexes are simple integers. If we change the AST then pretty printer will always flatten the indexes. That may be acceptable, it's not like pretty printer preserves all the formatting anyway.
In my opinion nested indexing is just an accidental consequence of the ability to index any expression. It's not necessary to support it in lvalue position, where arbitrary expressions aren't allowed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. Does this change do anything for nested indexing on the left hand side of a ~, or is that technically fine since it ends up inside a lpdf? I'm fuzzy on whether that counts as an l-value or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No change there, the "left-hand side" of a tilde statement is not an lvalue.
WardBrian
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
Submission Checklist
Fix #531.
Typechecker would check LValues as if they were RValues but codegen just flattens nested indexing. If these interpretations implied different type for the LValue then stanc3 would generate invalid C++ code. This case in now a type error.
For backwards compatibility, if the generated C++ code would have compiled before then the typechecker only emits a warning.
Single indexing may be arbitrarily nested as long as only the outermost index group contains multi-indexes (these cannot cause ambiguity)
Release notes
Deprecate nested multi-indexing on lvalues as it is inconsistent with rvalues.
Copyright and Licensing
Copyright holder: Niko Huurre
By submitting this pull request, the copyright holder is agreeing to
license the submitted work under the BSD 3-clause license (https://opensource.org/licenses/BSD-3-Clause)