-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
red-knot: infer multiplication for strings and integers (#13117)
## Summary The resulting type when multiplying a string literal by an integer literal is one of two types: - `StringLiteral`, in the case where it is a reasonably small resulting string (arbitrarily bounded here to 4096 bytes, roughly a page on many operating systems), including the fully expanded string. - `LiteralString`, matching Pyright etc., for strings larger than that. Additionally: - Switch to using `Box<str>` instead of `String` for the internal value of `StringLiteral`, saving some non-trivial byte overhead (and keeping the total number of allocations the same). - Be clearer and more accurate about which types we ought to defer to in `StringLiteral` and `LiteralString` member lookup. ## Test Plan Added a test case covering multiplication times integers: positive, negative, zero, and in and out of bounds. --------- Co-authored-by: Alex Waygood <alex.waygood@gmail.com> Co-authored-by: Carl Meyer <carl@astral.sh>
- Loading branch information
1 parent
96b42b0
commit aba1802
Showing
3 changed files
with
88 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters