-
-
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
Fix 'NamedTupleLiteral#[]` to raise an error for invalid key type #7158
Fix 'NamedTupleLiteral#[]` to raise an error for invalid key type #7158
Conversation
And also update doc.
@@ -937,7 +937,7 @@ module Crystal | |||
when StringLiteral | |||
key = key.value | |||
else | |||
return NilLiteral.new | |||
raise "argument to [] must be a symbol or string, not #{key.class_desc}:\n\n#{key}" |
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'd suggest avoiding newlines in exception messages if possible.
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 think this is right. With this, there's no way to know whether a key is present or not in the named tuple literal. |
Guess we need |
Maybe. Or just returning |
AFAIK this exception is raised only when a wrong type of node passed as a key, value can still be |
@Sija oh, right, I looked too quickly. Thanks! |
Ref #7153
And also update doc.
NamedTupleLiteral#[]=
denies key typed neitherStringLiteral
,SymbolLiteral
norMacroId
already. I thinkNamedTuple#[]
should do same.