-
Notifications
You must be signed in to change notification settings - Fork 281
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
can't emit primary constructor default parameters #133
Milestone
Comments
whoops, missed |
Ok, sorry for the goof, I'm re-opening because the exact code block above can't be generated. |
What did you try? My guess would be a constructor param with a default and
then a property which is initialized to the constructor param.
…On Sun, Jun 18, 2017, 9:23 PM Vishnu Rajeevan ***@***.***> wrote:
Reopened #133 <#133>.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#133 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAEEEdxW-JtENNbTFEWJGwk5piyfj-pZks5sFc2EgaJpZM4N9qAM>
.
|
I tried that but it moves initialization out of the inline syntax. I'll
paste a code sample when I'm not afk.
On Sun, Jun 18, 2017, 10:02 PM Jake Wharton <notifications@github.com>
wrote:
… What did you try? My guess would be a constructor param with a default and
then a property which is initialized to the constructor param.
On Sun, Jun 18, 2017, 9:23 PM Vishnu Rajeevan ***@***.***>
wrote:
> Reopened #133 <#133>.
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <#133 (comment)>, or
mute
> the thread
> <
https://github.com/notifications/unsubscribe-auth/AAEEEdxW-JtENNbTFEWJGwk5piyfj-pZks5sFc2EgaJpZM4N9qAM
>
> .
>
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#133 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABYqRXNYacNu634Uo1uOVZN5N0Qvi_3hks5sFda8gaJpZM4N9qAM>
.
|
@Test fun constructorWithDefaultParamValue() {
val type = TypeSpec.classBuilder("Taco")
.primaryConstructor(FunSpec.constructorBuilder()
.addParameter(ParameterSpec.builder("a", Int::class).defaultValue("1").build())
.addParameter(ParameterSpec.builder("b", String::class.asTypeName().asNullable())
.defaultValue("null")
.build())
.build())
.addProperty(PropertySpec.builder("a", Int::class)
.initializer("a")
.build())
.addProperty(PropertySpec.builder("b", String::class.asTypeName().asNullable())
.initializer("b")
.build())
.build()
assertThat(toString(type)).isEqualTo("""
|package com.squareup.tacos
|
|import kotlin.Int
|import kotlin.String
|
|class Taco(val a: Int = 1, val b: kotlin.String? = null)
|""".trimMargin())
} actual output: class Taco(val a: Int, val b: kotlin.String?) There's a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The text was updated successfully, but these errors were encountered: