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

WRONG_NAME_OF_VARIABLE_INSIDE_ACCESSOR false positive #1935

Open
DmitriyZaitsev opened this issue Jul 1, 2024 · 0 comments
Open

WRONG_NAME_OF_VARIABLE_INSIDE_ACCESSOR false positive #1935

DmitriyZaitsev opened this issue Jul 1, 2024 · 0 comments
Labels
bug Something isn't working good first issue Good for newcomers
Milestone

Comments

@DmitriyZaitsev
Copy link

Describe the bug

Here's a piece of code I have:

public abstract class Observable<T> {
    public abstract val value: T

    public abstract fun subscribe(subscriber: Subscriber<T>): Subscription

    public inline fun <R> transform(crossinline block: Transform<T, R>): Observable<R> =
        object : Observable<R>() {
            override fun subscribe(subscriber: Subscriber<R>): Subscription =
                this@Observable.subscribe { subscriber(block(it)) }

            @Suppress("WRONG_NAME_OF_VARIABLE_INSIDE_ACCESSOR")
            override val value: R
                get() = block(this@Observable.value) // I can't use the `field` property here
        }

    public companion object
}

The problem is diktat claims I have to use a field property instead of [email protected] which isn't technically possible in this case.
Perhaps the case is non-trivial for the parser, and if I had used a named private class instead of an anonymous object, this could have been avoided, but I think I should point out that such snippets happen too.

Environment information

  • diktat version: 2.0.0
  • build tool (maven/gradle): Gradle
  • how is diktat run (CLI, plugin, etc.): plugin
  • kotlin version: 2.0.0
  • operating system: macOS Sonoma 14.3
@DmitriyZaitsev DmitriyZaitsev added the bug Something isn't working label Jul 1, 2024
@0x6675636b796f75676974687562 0x6675636b796f75676974687562 added this to the 2.1.0 milestone Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants