-
Notifications
You must be signed in to change notification settings - Fork 47
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
Anonymous function in struct breaks indentation #432
Labels
Comments
It looks like an anonymous function and a long struct initializer are needed, but there doesn't need to be nesting: import std.stdio : writeln;
struct S {
ulong x;
ulong y;
ulong z;
ulong w;
}
immutable int function(int) f = (x) {
return x + 1111;
};
immutable S s = {
1111111111111111111,
1111111111111111111,
1111111111111111111,
1111111111111111111,
};
void main() {
} becomes: struct S
{
ulong x;
ulong y;
ulong z;
ulong w;
}
immutable int function(int) f = (x) { return x + 1111; };
immutable S s = {
1111111111111111111, 1111111111111111111, 1111111111111111111, 1111111111111111111,};
void main()
{
} |
WebFreak001
pushed a commit
that referenced
this issue
Oct 18, 2023
Overview: Array astInformation.structInitEndLocations is used to find index to use in astInformation.indentInfoSortedByEndLocation. Both are sorted, first is used to find the array index, second is accessed at that index to get brace indentation information. Problem: structInitEndLocations is generated from struct initializers exclusively while the brace information array also contains entries for function literal initializers. Thus when function literal init(s) are used, we get accumulating off by one errors in the second array: match value in structInitEndLocations and take that index: [3, 50] ^--> index 1 take brace indent information from that index: [3, 15, 50] | ^--> the one we want ^------> the one we get (function literal init) Solution: This guarantees that searching forward works. While better search strategies than linear are possible, this should be enough for any sane and most of the insane code files.
fixed in #590 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Input:
Output:
The text was updated successfully, but these errors were encountered: