dfmt icon indicating copy to clipboard operation
dfmt copied to clipboard

Anonymous function in struct breaks indentation

Open andy-hanson opened this issue 6 years ago • 1 comments

Input:

import std.stdio : writeln;

struct S {
	ulong x;
	ulong y;
	ulong function(ulong) f;
}

immutable S s = {
	1111111111111111111,
	1111111111111111111,
	(x) {
		return x + 1111;
	},
};

void main() {
	writeln(s.f(1));
}

Output:

import std.stdio : writeln;

struct S
{
    ulong x;
    ulong y;
    ulong function(ulong) f;
}

immutable S s = {
    1111111111111111111, 1111111111111111111, (x) { return x + 1111; },};

    void main()
    {
        writeln(s.f(1));
    }

andy-hanson avatar Feb 16 '19 07:02 andy-hanson

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()
    {
    }

andy-hanson avatar Feb 16 '19 07:02 andy-hanson

fixed in #590

WebFreak001 avatar Oct 22 '23 08:10 WebFreak001