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

Generate: val -> const val #42

Closed
Jesus13 opened this issue Nov 26, 2020 · 8 comments · Fixed by #70
Closed

Generate: val -> const val #42

Jesus13 opened this issue Nov 26, 2020 · 8 comments · Fixed by #70

Comments

@Jesus13
Copy link

Jesus13 commented Nov 26, 2020

Hi, maybe you can use const for generated config objects? Otherwise, you will not be able to make other constants. Constants will allow you to discard chunks of test code that should not be build for a production code.

const


internal object BuildKonfig {
  val FLAVOR: String = "dev"
}

->

internal object BuildKonfig {
  const val FLAVOR: String = "dev"
}
@yshrsmz
Copy link
Owner

yshrsmz commented Nov 28, 2020

If I remember correctly, expect/actual cannot be used with const.
It's possible to use const when BuildKonfig generates a simple object(when you don't provide target-specific config) but to keep consistency between the 2 cases, I think we should stick to the current implementation

@yshrsmz
Copy link
Owner

yshrsmz commented Dec 5, 2020

I'm going to close this for now.
Feel free to reopen this if you find a way.

@Prototik
Copy link
Contributor

Prototik commented Jun 5, 2022

@yshrsmz you can expose expect/actual const values with using @Suppress("CONST_VAL_WITHOUT_INITIALIZER") on the expect class.
I believe it's a bug in a compiler, and with this suppress i'm using it without any problems since kotlin 1.3.

@yshrsmz
Copy link
Owner

yshrsmz commented Jun 6, 2022

Hi @Prototik, thanks for the great information.

Do you know any source about this?

I found this youtrack issue, but it does not clarify if this is a bug or not
https://youtrack.jetbrains.com/issue/KT-18856/Can-we-have-expectactual-consts

@Prototik
Copy link
Contributor

Prototik commented Jun 6, 2022

No, I don't have any additional information about this, i discovered it by myself via looking to source code of kotlin compiler. I think this inspection just don't care about expect/actuals and should not be forced on expect declrations (due to fact expect cannot have default implementation of any sort).

I personally used it in my own BuildConfig-like plugin for a couple years already and don't encounter any issues with this suppress, and i think it's generally safe to do that (at least with opt-in behavior as I suggested in #70).

@Prototik
Copy link
Contributor

Prototik commented Jun 6, 2022

@yshrsmz I found this: it allows const actuals for non-const expects
JetBrains/kotlin@b4c8544

@yshrsmz
Copy link
Owner

yshrsmz commented Jun 6, 2022

That's great!
Let's move it forward 💪

@AlexanderEggers
Copy link

AlexanderEggers commented Apr 25, 2024

@Prototik I just noticed that the latest preview of Kotlin v2 and compose-multiplatform seems to have some issues with @Suppress("CONST_VAL_WITHOUT_INITIALIZER"). It is just a warning but I'm wondering if there is something which can be done to supress that. There are actually quite a lot of these now.

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

Successfully merging a pull request may close this issue.

4 participants