mirror of
https://github.com/dlang-community/dfmt.git
synced 2025-04-25 21:00:03 +03:00
Fix issue #432
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.
This commit is contained in:
parent
1e765fb781
commit
876bbe33c1
5 changed files with 75 additions and 0 deletions
|
@ -1053,6 +1053,14 @@ private:
|
|||
if (niBraceDepth > 0)
|
||||
niBraceDepth--;
|
||||
|
||||
// Account for possible function literals in this array which offset
|
||||
// the previously set index (pos). Fixes issue #432.
|
||||
while(astInformation.indentInfoSortedByEndLocation[pos].endLocation !=
|
||||
tokens[index].index)
|
||||
{
|
||||
pos++;
|
||||
}
|
||||
|
||||
auto indentInfo = astInformation.indentInfoSortedByEndLocation[pos];
|
||||
if (indentInfo.flags & BraceIndentInfoFlags.tempIndent)
|
||||
{
|
||||
|
|
17
tests/allman/issue0432.d.ref
Normal file
17
tests/allman/issue0432.d.ref
Normal file
|
@ -0,0 +1,17 @@
|
|||
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()
|
||||
{
|
||||
}
|
19
tests/issue0432.d
Normal file
19
tests/issue0432.d
Normal file
|
@ -0,0 +1,19 @@
|
|||
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()
|
||||
{
|
||||
}
|
16
tests/knr/issue0432.d.ref
Normal file
16
tests/knr/issue0432.d.ref
Normal file
|
@ -0,0 +1,16 @@
|
|||
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()
|
||||
{
|
||||
}
|
15
tests/otbs/issue0432.d.ref
Normal file
15
tests/otbs/issue0432.d.ref
Normal file
|
@ -0,0 +1,15 @@
|
|||
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() {
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue