Skip to content

[Bug]: Lambda body's first comparison split when arguments stay on the call line before a trailing lambda #1941

Closed

Description

@Qythyx

Description

Since 1.4.0 (#1865), the arguments before a trailing lambda stay on the call's line. For the input below, though, the line doesn't break after =>. The lambda body's first operand, type, stays on the call's line, and the rest of its == comparison wraps to the next line. The breaks after if ( and before the closing ) are also dropped, so the call ends in )) on the last line of the lambda.

Other calls with simpler lambdas in the same file format as #1865 describes.

Steps to Reproduce

CSharpier 1.4.0, with .editorconfig setting indent_style = tab and max_line_length = 120.

Input (1.3.0 leaves it unchanged):

public class C
{
	public async Task M()
	{
		if (true)
		{
			if (
				!await Database.ReplaceWithRetryAsync<Account>(
					credentials.AccountID,
					current =>
						type == PaymentMethodType.CreditCard && current.PaymentMethod.Card?.Registered is null
							? throw new DatabaseException(HttpStatusCode.BadRequest, "No registered card.")
							{
								RejectionReason = ServiceRejectionReason.CardNotRegistered,
							}
						: current.PaymentMethod.Type == type ? null
						: current with { PaymentMethod = current.PaymentMethod with { Type = type } }
				)
			)
			{
				return;
			}
		}
	}
}

Expected Behavior

The line breaks after =>, as #1865 describes. Otherwise CSharpier falls back to the 1.3.0 layout, with each argument on its own line and the breaks after if ( and before the closing ) kept.

Actual Behavior

public class C
{
	public async Task M()
	{
		if (true)
		{
			if (!await Database.ReplaceWithRetryAsync<Account>(credentials.AccountID, current => type
						== PaymentMethodType.CreditCard
					&& current.PaymentMethod.Card?.Registered is null
						? throw new DatabaseException(HttpStatusCode.BadRequest, "No registered card.")
						{
							RejectionReason = ServiceRejectionReason.CardNotRegistered,
						}
					: current.PaymentMethod.Type == type ? null
					: current with { PaymentMethod = current.PaymentMethod with { Type = type } }))
			{
				return;
			}
		}
	}
}

— Claude

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions