-
Notifications
You must be signed in to change notification settings - Fork 48
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
Issue #586 follow-up: Too little indentation if named arguments come after a newline #596
Open
danielzuncke
wants to merge
5
commits into
dlang-community:master
Choose a base branch
from
danielzuncke:issue586_followup
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bf56024
Issue 586: Fix indentation for named arguments
danielzuncke 0c7c86f
Issue 586: Update tests
danielzuncke f003239
Issue 586: Add tests with keep_line_breaks true
danielzuncke ea0db76
Merge branch 'dlang-community:master' into issue586_followup
danielzuncke 21b79d3
Adjust return value on missing token
danielzuncke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
void test() | ||
{ | ||
return Struct( | ||
foo: field.foo, | ||
bar: field.bar, | ||
baz: field.baz); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--keep_line_breaks true |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
void test() | ||
{ | ||
return Struct( | ||
foo: field.foo, | ||
bar: field.bar, | ||
baz: field.baz); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
void test() | ||
{ | ||
return Struct( | ||
foo: field.foo, | ||
bar: field.bar, | ||
baz: field.baz); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
void test() { | ||
return Struct( | ||
foo: field.foo, | ||
bar: field.bar, | ||
baz: field.baz); | ||
} |
Oops, something went wrong.
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.
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.
if you run this on
tokens == [tok!"...", tok!"comment"]
with start index = 0 and n = 1, this will return2
and cause a range error above in your usage (just in general if the token stream ends with comments and you start searching on it)Starting on 0 and searching negative will immediately go out of bounds and return size_t.max or a little bit below that.
I think you should make the function always return size_t.max for non-found tokens (and document it that way), since otherwise out-of-bounds tokens are too hard to check for and require knowledge about the tokens length, which isn't necessary for an API like this.
In your call site above, make sure you check the return value of this to not be size_t.max then. Right now it looks like that branch could easily cause a range error if the code ends in comments. (remember the array access is called also when it's not a named argument, since it itself is how it checks if it is a named argument or not, so the syntax may be arbitrary here) - however it's not that easy to get, I haven't been able to do it with a few tests right now yet. Just to defend against range errors I want you to test for it with a function that can generate one anyway.
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.
Sorry for the slow response
Don't get me wrong, I don't want to argue and will implement it how you like, but I think you might've missed something (or maybe I am, it's been a while). Please consider this 1. regarding the range error (= out of bounds access?), 2. regarding return value of the new function:
1.
Caller is in line Line 1807 and has surrounding code like this (most importantly Line 1794):
The if-condition in line 1794, that is true for the block in which
tokens[nextNonComment(1)]
is run, guarantees us that thetokens
array looks at least something like this (block below). So your example (if I understand it correctly) where the function is invoked with only trailing comments in the array isn't possible:I assume the range error that you see as a possibility is that one, otherwise iirc
tokens[nextNonComment(1)].index
is the position in the file andcanFind
should be eithertrue
orfalse
, so I don't see the need for additional access checks (or a reasonable way to implement any,peekIs
finding a non-comment should be the appropriate check).For the same reason I think this is a moot point since while the
tok!":"
may not be related to named args, it only needs to exist for the array access to not throw:If I am not mistaken, there is currently no way to write a testcase that fails with an out of bounds error for
tokens[nextNonComment(1)]
, even when writing the tokens array manually and then invoking the surrounding function.2.
I changed the return value when no token is found from
nextNonComment()
, but I am not convinced this is a good thing: the function is a private member ofstruct TokenFormatter
so anyone calling it also has access totokens.length
(I don't understand how out-of-bounds tokens would be hard to check for when that's accessible).With the explicit return of
size_t.max
(for a variable expecting an index) I can see how it encourages to test forreturnedIndex == size_t.max
instead ofreturnedIndex < tokens.length
which I assume can easily have much worse consequences if another error is at play.