Skip to content
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

Fix issue #432 #590

Merged
merged 3 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/dfmt/formatter.d
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,21 @@ private:
if (niBraceDepth > 0)
niBraceDepth--;

// Account for possible function literals in this array which offset
// the previously set index (pos). Fixes issue #432.
size_t newPos = pos;
while(astInformation.indentInfoSortedByEndLocation[newPos].endLocation <
tokens[index].index)
{
newPos++;
}

if (astInformation.indentInfoSortedByEndLocation[newPos].endLocation ==
tokens[index].index)
{
pos = newPos;
}

auto indentInfo = astInformation.indentInfoSortedByEndLocation[pos];
if (indentInfo.flags & BraceIndentInfoFlags.tempIndent)
{
Expand Down
40 changes: 40 additions & 0 deletions tests/allman/issue0432.d.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
struct S1
{
ulong x;
ulong y;
ulong function(ulong) f;
}

struct S2
{
ulong x;
ulong y;
ulong z;
ulong w;
}

// -----------------------------------------------------------------------------
// Example 1
// Anonymous function in struct, long struct initializer

immutable S1 s1 = {
1111111111111111111, 1111111111111111111, (x) { return x + 1111; },
};

void f1()
{
}

// -----------------------------------------------------------------------------
// Example 2
// Anonymous function anywhere, long struct initializer

int function(int) f2 = (x) { return x + 1111; };

immutable S2 s = {
1111111111111111111, 1111111111111111111, 1111111111111111111, 1111111111111111111,
};

void f2()
{
}
38 changes: 38 additions & 0 deletions tests/issue0432.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
struct S1
{
ulong x;
ulong y;
ulong function(ulong)f;
}

struct S2
{
ulong x;
ulong y;
ulong z;
ulong w;
}

// -----------------------------------------------------------------------------
// Example 1
// Anonymous function in struct, long struct initializer

immutable S1 s1 = {
1111111111111111111, 1111111111111111111, (x) { return x + 1111; },};

void f1()
{
}

// -----------------------------------------------------------------------------
// Example 2
// Anonymous function anywhere, long struct initializer

int function(int) f2 = (x) { return x + 1111; };

immutable S2 s = {
1111111111111111111, 1111111111111111111, 1111111111111111111, 1111111111111111111,};

void f2()
{
}
38 changes: 38 additions & 0 deletions tests/knr/issue0432.d.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
struct S1 {
ulong x;
ulong y;
ulong function(ulong) f;
}

struct S2 {
ulong x;
ulong y;
ulong z;
ulong w;
}

// -----------------------------------------------------------------------------
// Example 1
// Anonymous function in struct, long struct initializer

immutable S1 s1 = {
1111111111111111111, 1111111111111111111, (x) { return x + 1111; },
};

void f1()
{
}

// -----------------------------------------------------------------------------
// Example 2
// Anonymous function anywhere, long struct initializer

int function(int) f2 = (x) { return x + 1111; };

immutable S2 s = {
1111111111111111111, 1111111111111111111, 1111111111111111111, 1111111111111111111,
};

void f2()
{
}
36 changes: 36 additions & 0 deletions tests/otbs/issue0432.d.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
struct S1 {
ulong x;
ulong y;
ulong function(ulong) f;
}

struct S2 {
ulong x;
ulong y;
ulong z;
ulong w;
}

// -----------------------------------------------------------------------------
// Example 1
// Anonymous function in struct, long struct initializer

immutable S1 s1 = {
1111111111111111111, 1111111111111111111, (x) { return x + 1111; },
};

void f1() {
}

// -----------------------------------------------------------------------------
// Example 2
// Anonymous function anywhere, long struct initializer

int function(int) f2 = (x) { return x + 1111; };

immutable S2 s = {
1111111111111111111, 1111111111111111111, 1111111111111111111, 1111111111111111111,
};

void f2() {
}
Loading