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

const val with Char.code property #3913

Closed
tateisu opened this issue Jun 27, 2021 · 11 comments
Closed

const val with Char.code property #3913

tateisu opened this issue Jun 27, 2021 · 11 comments

Comments

@tateisu
Copy link

tateisu commented Jun 27, 2021

gradlew detektRcDebug
(snip)
error: const 'val' initializer should be a constant value
    private const val cpColon = ':'.code
(snip)

Expected Behavior

this is not an error, maybe false positive.

Observed Behavior

Steps to Reproduce

Context

Your Environment

  • Version of detekt used:
  • Version of Gradle used (if applicable):
  • Gradle scan link (add --scan option when running the gradle task):
  • Operating System and version:
  • Link to your project (if it's a public repository):
@cortinico
Copy link
Member

this is not an error, maybe false positive.

Can you provide more information?
I'm unsure if this is a compilation error or a detekt report.
If it's a detekt report, which rule is being reported?
Can you also provide the code snippet?
Also can I ask you to fill in the "Your Environment" section?

@tateisu
Copy link
Author

tateisu commented Jun 28, 2021

detekt 1.17.1
kotlin 1.5.10
Android Studio 4.2.1
Build #AI-202.7660.26.42.7351085, built on May 11, 2021
Runtime version: 11.0.8+10-b944.6842174 amd64
VM: OpenJDK 64-Bit Server VM by N/A
Windows 10 10.0
GC: G1 Young Generation, G1 Old Generation
Memory: 4096M
Cores: 24
Registry: external.system.auto.import.disabled=true
Non-Bundled Plugins: com.dubreuia, com.notime.intellijPlugin.backgroundImagePlus, org.jetbrains.kotlin, izhangzhihao.rainbow.brackets
(projectDir)>gradlew detektRcDebug

> Task :app:detektRcDebug
\(projectDir)\app\src\main\java\jp\juggler\subwaytooter\ActAccountSetting.kt:321:40: error: unresolved reference: BuildConfig
        btnPushSubscriptionNotForce.vg(BuildConfig.DEBUG)
                                       ^
\(projectDir)\app\src\main\java\jp\juggler\subwaytooter\App1.kt:220:29: error: unresolved reference: BuildConfig
            "SubwayTooter/${BuildConfig.VERSION_NAME} Android/${Build.VERSION.RELEASE}"
                            ^
\(projectDir)\app\src\main\java\jp\juggler\subwaytooter\util\EmojiDecoder.kt:31:33: error: const 'val' initializer should be a constant value
    private const val cpColon = ':'.code
                                ^
\(projectDir)\app\src\main\java\jp\juggler\subwaytooter\util\EmojiDecoder.kt:33:32: error: const 'val' initializer should be a constant value
    private const val cpZwsp = '\u200B'.code
                               ^
\(projectDir)\app\src\main\java\jp\juggler\subwaytooter\util\EmojiDecoder.kt:249:40: error: const 'val' initializer should be a constant value
    private const val codepointColon = ':'.code
                                       ^
\(projectDir)\app\src\main\java\jp\juggler\util\Benchmark.kt:3:32: error: unresolved reference: BuildConfig
import jp.juggler.subwaytooter.BuildConfig
                               ^
\(projectDir)\app\src\main\java\jp\juggler\util\Benchmark.kt:9:33: error: unresolved reference: BuildConfig
val benchmarkLimitDefault = if (BuildConfig.DEBUG) 10L else 100L
                                ^
complexity - 3d 19h 20min debt
(snip)

Overall debt: 3d 19h 30min


> Task :app:detektRcDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:detektRcDebug'.
> Build failed with 276 weighted issues.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 30s
56 actionable tasks: 1 executed, 55 up-to-date

@BraisGabin
Copy link
Member

I'm not sure and I'm far from a computer to check it. Could this code be valid in kotlin 1.5 but invalid in kotlin 1.4? I think that detekt uses under the hood the Compiler from 1.4 so that could be the issue.

@tateisu
Copy link
Author

tateisu commented Jun 28, 2021

maybe yes, Char.code is introduced at kotlin 1.5

@BraisGabin
Copy link
Member

Probably this issue would be fixed by using https://github.com/detekt/detekt-compiler-plugin. Another reason for us to get feature parity with that project.

@tateisu
Copy link
Author

tateisu commented Jun 28, 2021

Is there example that apply the plugin to Android Studio project?
I can't find it and I got many error when I try.

@cortinico
Copy link
Member

Is there example that apply the plugin to Android Studio project?
I can't find it and I got many error when I try.

Ideally this should suffice:
https://github.com/detekt/detekt-compiler-plugin/blob/36e3dec680f404b02f21a6df7f030913015154b3/build.gradle.kts#L1-L11

I'm waiting to have 1.18.0 to revamp a bit the documentation for the compiler plugin 👍

@github-actions
Copy link

github-actions bot commented Nov 2, 2021

This issue is stale because it has been open 90 days with no activity. Please comment or this will be closed in 7 days.

@github-actions github-actions bot added the stale label Nov 2, 2021
@BraisGabin BraisGabin removed the stale label Nov 2, 2021
@cortinico
Copy link
Member

As a side note: I believe this will be fixed by #4106

@github-actions
Copy link

github-actions bot commented Feb 7, 2022

This issue is stale because it has been open 90 days with no activity. Please comment or this will be closed in 7 days.

@github-actions github-actions bot added the stale label Feb 7, 2022
@cortinico
Copy link
Member

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

No branches or pull requests

3 participants