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

Anonymous class as function parameter messes up entirely #545

Open
FeepingCreature opened this issue Nov 18, 2021 · 2 comments
Open

Anonymous class as function parameter messes up entirely #545

FeepingCreature opened this issue Nov 18, 2021 · 2 comments
Labels

Comments

@FeepingCreature
Copy link
Contributor

FeepingCreature commented Nov 18, 2021

Consider:

void main()
{
    call(new class Object
    {
        void method()
        {
            call;
        }
    });
}

dfmt's take:

void main()
{
    call(new class Object
        {
        void method()
        {
            call;}
        }
);
    }

And from there on, the entire rest of the file is misindented by one.

@danielzuncke
Copy link
Contributor

danielzuncke commented Oct 21, 2023

What is actually the expected brace style? Since this is continues a statement across lines it could arguably be indented one deeper:

void main()
{
    call(new class Object
        {
            void method()
            {
                call;
            }
        }
    );
}

The one suggested is commonly used across languages and it seems reasonable to use.

Also consider this:
What default behaviour is reasonable for the case that anon class doesn't appear in the first line of the function args? See cases below. Should whatever gets chosen there have influence on the choice of how it's indented if it's the first argument?

void f()
{
    // Should it be this (case 1):
    writeln("Anonymous object does not begin on the first line",
        new class Object
    {
        void method()
        {
            writeln;
        }
    });

    // Or this (case 2):
    writeln("Anonymous object does not begin on the first line",
        new class Object
        {
            void method()
            {
                writeln;
            }
        });

    // Or this (case 3):
    writeln("Anonymous object does not begin on the first line",
        new class Object
        {
            void method()
            {
                writeln;
            }
        }
    );
}

I think case 2 since I don't think having closing parentheses on the same indent level as opening is reasonable (case 3); case 1 seems to me like an obvious no.

I think the behaviour should be consistent with braces in parenthesis in general, which is currently:
(I feel like brace case 2 might actually be more reasonable if braced argument is not the first one?)

void g()
{
    // Current behaviour brace on first line:
    writeln({
        int longVarNameToForceLineBreak = 5;
        writeln(longVarNameToForceLineBreak);
        return longVarNameToForceLineBreak * 2;
    });

    // Current behaviour brace not on first line (brace case 1):
    writeln("Brace does not begin on the first line",
    {
        int longVarNameToForceLineBreak = 5;
        writeln(longVarNameToForceLineBreak);
        return longVarNameToForceLineBreak * 2;
    });

    // Current behaviour brace not on first line (brace case 2):
    writeln("Brace does not begin on the first line",
        {
            int longVarNameToForceLineBreak = 5;
            writeln(longVarNameToForceLineBreak);
            return longVarNameToForceLineBreak * 2;
        });
}

@WebFreak001
Copy link
Member

I agree, case 2 seems good and in general keeping consistency with existing parentheses rules

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants