-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Support tuple metaclass indexers with non-literal arguments #11834
Support tuple metaclass indexers with non-literal arguments #11834
Conversation
Thinking of #12005, to me the pattern FIELD = :field
tuple[FIELD] makes perfect sense; however, it won't work as expected since it will return the union of all the types of the tuple even if the value is known at compile time. How hard is it to consider this case specially? |
Very easy! But is there a reason to discuss this here instead of in #12005? |
No, it doesn't make sense for it to be here. (me to brain rn: GH comments are not a chat system GH comments are not a chat system GH comments are not a chat system ....) |
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.
Thanks! Just one very minor concern.
…aclass-indexer-var
Implements the following class methods:
Tuple.[](index : Int)
Tuple.[]?(index : Int)
NamedTuple.[](key : Symbol | String)
NamedTuple.[]?(key : Symbol | String)
They already work when the index is an integer literal, or when the key is a symbol or string literal. With this PR regular, non-literal variables also work.
Also "adds" a
Tuple.[](range : Range)
overload which always fails to compile unlessrange
is a literal, similar to its non-metaclass counterpart.