Skip to content

[2.9.7] Regression formatting return-statement with parentheses #921

Closed

Description

@boris-petrov

Prettier-Java 2.9.7

Playground link

--print-width 80

Input:

return (
  a(b) && a.a().a()
    ? a.a()
    : a
).toString();

Output:

return (a(b) && a.a().a()
  ? a.a()
  : a
).toString();

Expected behavior:

return (
  a(b) && a.a().a() ? a.a() : a
).toString();

Because Prettier for JS does this

Activity

  1. boris-petrov commented on Jun 23, 2026

    @boris-petrov
    Author

    @jtkiesel thanks for fixing this and congrats on the new release! However, I believe it broke some things. For example:

    observable.doOnSubscribe(disposable -> querySubscription = disposable);

    Where observable is an RxJava io.reactivex.rxjava3.core.Observable. The method's signature is:

    Observable<IImmutableMap<String, Object>> io.reactivex.rxjava3.core.Observable.doOnSubscribe(
        @NonNull Consumer<? super Disposable> onSubscribe
    )
    

    Note that the method argument is a Consumer. Adding parentheses around the body (as 2.10.0 does - observable.doOnSubscribe(disposable -> (querySubscription = disposable));) makes it not compile:

    Void methods cannot return a value
    

    TIL that there is a difference between these two lines. 😄 But this is a regression nonetheless.

    This may or may not be similar to #946.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions