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

class-signature rule incorrectly forces removal of primary no-argument constructor #2749

Closed
alex-shinn opened this issue Jul 22, 2024 · 2 comments

Comments

@alex-shinn
Copy link

alex-shinn commented Jul 22, 2024

Expected Behavior

As a contrived example, but trimmed down from a real example, consider the file Foo.kt:

class Foo() {
    constructor(name: String) : this() {
    }
}

This should pass lint checks with no warnings.

Observed Behavior

ktlint reports a warning:

Foo.kt:1:10: No parenthesis expected (standard:class-signature)
12:30:54.868 [main] WARN com.pinterest.ktlint.cli.internal.KtlintCommandLine -- Lint has found errors than can be autocorrected using 'ktlint --format'

Summary error count (descending) by rule:
  standard:class-signature: 1

And if --format is enabled automatically removes the primary constructor for Foo:

class Foo {

however that constructor is actually being used by the other constructor, causing the following compilation error:

tmp/Foo.kt:8:13: error: supertype initialization is impossible without primary constructor
class Foo {
            ^
tmp/Foo.kt:9:37: error: no value passed for parameter 'name'
    constructor(name: String) : this() {
                                    ^Target //tmp:FooLib failed to build

Your Environment

  • Version of ktlint used: 1.3.0 (as provided by bazel rules_kotlin)
  • No .editorconfig settings
  • Name and version (or code for custom task) of integration used (bazel 7.2.1 with rules_kotlin 1.9.6):
  • Operating System and version: Linux vm-shared 6.5.0-1016-gcp #16~22.04.1-Ubuntu SMP Sat Mar 9 00:58:37 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
@paul-dingemans
Copy link
Collaborator

This has already been fixed by #2717 in version 1.3.1.

@paul-dingemans paul-dingemans closed this as not planned Won't fix, can't repro, duplicate, stale Jul 23, 2024
@alex-shinn
Copy link
Author

Thanks!

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