Add ArrayLiteral#* and StringLiteral#*#16154
Add ArrayLiteral#* and StringLiteral#*#16154straight-shoota merged 2 commits intocrystal-lang:masterfrom
ArrayLiteral#* and StringLiteral#*#16154Conversation
| it "executes *" do | ||
| assert_macro %({{["na"] * 5}}), %(["na", "na", "na", "na", "na"]) | ||
| end |
There was a problem hiding this comment.
Since the newly added functionality was placed within interpret_array_or_tuple_method, I believe we're missing tests for TupleLiteral#* case.
| # Similar to `Array#*` | ||
| def *(other : NumberLiteral) : ArrayLiteral | ||
| end |
There was a problem hiding this comment.
Since the newly added functionality was placed within interpret_array_or_tuple_method, similar comment is missing from TupleLiteral definition within the same file.
| num = arg.to_number | ||
|
|
||
| unless num.is_a?(Int) | ||
| arg.raise "argument to StringLiteral#* cannot be a float" |
There was a problem hiding this comment.
Suggestion: the error message could be improved as it states the problem, but not a solution. A better alternative would be explicitly stating what the expected type is.
| arg.raise "argument to StringLiteral#* cannot be a float" | |
| arg.raise "argument to StringLiteral#* must be an integer" |
| num = arg.to_number | ||
|
|
||
| unless num.is_a?(Int) | ||
| arg.raise "argument to ArrayLiteral#* cannot be a float" |
There was a problem hiding this comment.
Suggestion: error message could be improved as it states the problem, but not a solution. A better alternative would be explicitly stating what the expected type is.
| arg.raise "argument to ArrayLiteral#* cannot be a float" | |
| arg.raise "argument to ArrayLiteral#* must be an integer" |
Also fixes some error messages. Co-Authored-By: Sijawusz Pur Rahnama <sija@sija.pl>
To mirror
Array#*andString#*. New specs added to cover these.