Fix integers with LL suffix#299
Open
davispuh wants to merge 1 commit intojacob-carlborg:masterfrom
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates dstep’s macro literal translation so C integer literals using the LL (long long) suffix are emitted as valid D integer literals (D doesn’t allow LL).
Changes:
- Detects
LLat the end of an integer literal suffix and collapses it to a singleL. - Applies the same suffix normalization in both the octal-literal translation path and the non-octal path.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
97
to
+100
| alias pred = (dchar x) => (x == 'u' || x == 'U' || x == 'L'); | ||
| auto integer = literal.spelling.stripRight!pred; | ||
| auto uinteger = integer.stripLeft!(x => x == '+' || x == '-'); | ||
| auto suffix = literal.spelling[integer.length .. $]; |
Comment on lines
+107
to
+116
| if (suffix.length >= 2 && suffix[$-2..$] == "LL") | ||
| { | ||
| suffix = suffix.chop; | ||
| } | ||
| auto core = uinteger[0 .. $ - 1].stripLeft('0') ~ uinteger[$ - 1]; | ||
| return "octal!" ~ core ~ suffix; | ||
| } else if (suffix.length >= 2 && suffix[$-2..$] == "LL") | ||
| { | ||
| suffix = suffix.chop; | ||
| return integer ~ suffix; |
Comment on lines
+113
to
+116
| } else if (suffix.length >= 2 && suffix[$-2..$] == "LL") | ||
| { | ||
| suffix = suffix.chop; | ||
| return integer ~ suffix; |
jacob-carlborg
requested changes
Mar 19, 2026
Owner
jacob-carlborg
left a comment
There was a problem hiding this comment.
Comments by Copilot are reasonable, especially about missing tests.
| { | ||
| (*context.imports).add("std.conv : octal"); | ||
| auto suffix = literal.spelling[integer.length .. $]; | ||
| if (suffix.length >= 2 && suffix[$-2..$] == "LL") |
Owner
There was a problem hiding this comment.
There's a function in the standard library that checks if a string ends with another string, can't that be used? https://dlang.org/phobos/std_algorithm_searching.html#.endsWith
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Consider
a.hwith:Currently
dstepwould produceWhich is not valid D code because D language doesn't have
LLsuffix.This PR fixes that so in such case result will be: