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

ktfmt fails to parse angle brackets in certain cases #51

Closed
myabc opened this issue Jul 2, 2020 · 3 comments
Closed

ktfmt fails to parse angle brackets in certain cases #51

myabc opened this issue Jul 2, 2020 · 3 comments

Comments

@myabc
Copy link

myabc commented Jul 2, 2020

Example 1. In the case of a class inheriting from more than one class or interface, angle bracket syntax is used to denote the supertype from which the inherited implementation is taken.

package com.myandroidapp

import android.app.Application
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner

class App : Application(), DefaultLifecycleObserver {

  override fun onCreate() {
    // com.google.googlejavaformat.FormattingError: 11:15: error: did not generate token "<"
    super<Application>.onCreate()
   // etc.
  }
}

Expected behaviour: ktfmt parses/reformats the source code.
Actual behaviour: results in an error similar to com.google.googlejavaformat.FormattingError: 11:15: error: did not generate token "<"

Update: appears to be fixed in 2c17040

Example 2 Type Parameters in Annotations: for example, the @TypeParceler annotation from Kotlinx's Parcelize library allows you to explicitly specify an implementation of Parcelable for types that do not have built-in serialisation support.

import java.util.UUID

import kotlinx.android.parcel.*

@Parcelize
@TypeParceler<UUID, UUIDParceler>()
data class User(
  val id: UUID
)

Expected behaviour: ktfmt parses/reformats the source code.
Actual behaviour: results in an error similar to com.google.googlejavaformat.FormattingError: 5:21: error: expected token: '('; generated < instead or 5:21: error: expected token: 'data'; generated < instead if the empty parentheses are removed.


Using ktfmt 0.13 with Spotless plugin for Gradle 4.4.0; Gradle 6.5.0. Targeting Kotlin 1.3.72.

@myabc
Copy link
Author

myabc commented Jul 2, 2020

Since looked through the commit history. It appears this commit addresses the issue highlighted in the first example: 2c17040

@cgrushko
Copy link
Contributor

cgrushko commented Jul 2, 2020

@myabc thanks! if I understand correctly, it's a matter of releasing a new version?
(also, we should think about how to automate releases...)

@myabc
Copy link
Author

myabc commented Jul 2, 2020

@cgrushko I built ktfmt from source and installed it into my local Maven repository. I can confirm that 2c17040 does the trick: ktfmt no longer crashes on calls to super with angle bracket syntax to specify the supertype.

I understand correctly, it's a matter of releasing a new version?

If only... 🙂

AFAICT the second issue I listed is still present on master. While it'd be great to see a release with the fix for multiple implementation inheritance, that release would not address all angle bracket syntax bugs.

facebook-github-bot pushed a commit that referenced this issue Jul 7, 2020
Summary:
Release Notes:
* Handle annotations with type arguments (fixes #48)
* Fit annotations in one line when possible
* Handle multi-annotations with use-site targets (fixes #51)

Reviewed By: strulovich

Differential Revision: D22395554

fbshipit-source-id: 4faf371b69edb95431ad244d8fd869a7fa942d4b
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

2 participants