kopykat-kt / kopykat

Little utilities for more pleasant immutable data in Kotlin
Other
280 stars 16 forks source link

Issue with Nullable types #70

Closed slawluc closed 1 year ago

slawluc commented 1 year ago

Thanks for taking the time to create this utility as an alternative to optics. Whilst trying it out, I came across the following issue. Time permitting, I'll familiarise myself with the code base and attempt a pull request.

Given these gradle settings

buildscript {
    dependencies {
        .....
        classpath "com.google.devtools.ksp:symbol-processing-gradle-plugin:1.7.10-1.0.6"
    }
}

dependencies {
    .......
    ksp("at.kopyk:kopykat-ksp:1.0-rc7")
    compileOnly("at.kopyk:kopykat-annotations:1.0-rc7")
}

ksp {
    arg("generate","annotated")
    arg("mutableCopy", "true")
    arg("copyMap", "true")
    arg("hierarchyCopy", "true")
    arg("superCopy", "false")
}

When I attempt to annotate this class with @CopyExtensions a nullable middle name

@CopyExtensions
data class Person(
    val firstName: String,
    val middleName: String?,
    val surname: String
)

Then I get the following compilation error

e: /.../build/generated/ksp/main/kotlin/com/_____/com.******.Person$Mutable.kt: (26, 18): Type mismatch: inferred type is String? but String was expected

The compilation error in generated code is on the 'middleName'

@`Person$DslMarker`
public class `Person$Mutable`(
  public var firstName: String,
  public var middleName: String,
  public var surname: String,
  public val old: Person,
)

public fun `Person$Mutable`.freeze(): Person =
    com.business.model.internal.Person(firstName = firstName, middleName = middleName,
    surname = surname)

public fun Person.toMutable(): `Person$Mutable` =
    com.business.model.`internal`.`Person$Mutable`(old = this, firstName = firstName,
    middleName = middleName, surname = surname)
serras commented 1 year ago

This should be fixed by #63. We'll release a new version soon, once #68 is merged.

serras commented 1 year ago

@slawluc would it be possible for you to check with the new 1.0-rc8 release? This should fix the bug, but it's better to be safe than sorry.

slawluc commented 1 year ago

@serras - I updated my test project to 1.0-rc8 as suggested and it does resolve the issue. Thanks!