y9vad9/implier

`toPatched` requires Mutable variant even though it doesn't need it

y9vad9 opened this issue · 0 comments

Describe the bug
toPatched function requires Mutable variant of entity even though it doesn't need it.
It generates next code:

public fun UserEntity.toPatched(patch: UserEntity): UserEntity {
  val isMutable = this is MutableUserEntity
  val base = if(isMutable) this as MutableUserEntity else this.toMutable()
  patch.id?.let{ 
    base.id = it
  }
  patch.firstName?.let{ 
    base.firstName = it
  }
  patch.lastName?.let{ 
    base.lastName = it
  }
  return if(isMutable) this else base.toImmutable()
}

To Reproduce
Steps to reproduce the behavior:

  1. Create entity with annotation DtoImpl without using MutableImpl (use ImmutableImpl)
  2. Run generation
  3. Try to build the project
  4. See error

Expected behavior
I think it shouldn't use mutable variant (almost useless) at all or use it only when mutable variant is available (if we don't need producing instances).