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

Formatting of annotations may change semantic meaning #234

Closed
bethcutler opened this issue May 17, 2021 · 3 comments
Closed

Formatting of annotations may change semantic meaning #234

bethcutler opened this issue May 17, 2021 · 3 comments

Comments

@bethcutler
Copy link
Contributor

Annotations are generally moved to the same line, but this may change the scope of the annotation.

Original code:

fun <T : Any?> testCasting(test: T, foo: String, bar: String): T {
  if (!foo.isEmpty()) {
    @Suppress("UNCHECKED_CAST")
    bar.isEmpty() || return (null as T)
  }
  return test
}

Formatted code:

fun <T : Any?> testCasting(test: T, foo: String, bar: String): T {
  if (!foo.isEmpty()) {
    @Suppress("UNCHECKED_CAST") bar.isEmpty() || return (null as T)
  }
  return test
}

After formatting, the Suppress annotation only applies on the first half of the expression, not the part of the expression where the cast actually occurs.

@cgrushko
Copy link
Contributor

cgrushko commented Jun 7, 2021

cc @strulovich

@strulovich
Copy link
Contributor

I guess this is a problem in both ways, since converting case 2 into case 1 would also be a bug no? Does this mean we must preserve spacing on annotations? (At least for expressions)?

@davidtorosyan
Copy link
Contributor

So be43fdb fixed #247, which I think is a duplicate of this, so closing this out as well. Please reopen if I'm wrong!

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

No branches or pull requests

4 participants