Skip to content

Support Kotlin null safety #1257

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

Open
volivan239 opened this issue Oct 28, 2022 · 0 comments
Open

Support Kotlin null safety #1257

volivan239 opened this issue Oct 28, 2022 · 0 comments
Assignees
Labels
comp-codegen Issue is related to code generator comp-symbolic-engine Issue is related to the symbolic execution engine ctg-bug Issue is a bug lang-kotlin Issue is related to Kotlin language support

Comments

@volivan239
Copy link
Collaborator

Description

We have to properly handle Kotlin nullable and not-nullable types to produce correct tests:

  1. We shouldn't generate models in which value of not-nullable type is null
  2. We should put ?. and !! in generated files where it is needed.
  3. We should properly handle possibly-null values returned by java code.

There were some attempts to support this, but this is only partially supported currently.

To Reproduce

There are many cases where behavior is incorrect. For example, launch action on the following class:

class NullabilityIssuesExample(var x: Int) {
    fun copyWithX(new_x: Int?): NullabilityIssuesExample? {
        if (new_x == null)
            return null
        return NullabilityIssuesExample(x + new_x)
    }
}

Expected behavior

Correct tests are generated.

Actual behavior

Among others, the following test is generated:

fun testCopyWithX2() {
    val nullabilityIssuesExample = NullabilityIssuesExample(-255)
    val new_x = -255
    
    val actual = nullabilityIssuesExample.copyWithX(new_x)
    
    val expected = NullabilityIssuesExample(0)
    expected.x = -510
    val expectedX = expected.x
    val actualX = actual.x
    assertEquals(expectedX, actualX)   
}

Additional context

This is an old big issue, which may be solved step by step.

@volivan239 volivan239 added ctg-bug Issue is a bug comp-codegen Issue is related to code generator comp-symbolic-engine Issue is related to the symbolic execution engine lang-kotlin Issue is related to Kotlin language support labels Oct 28, 2022
@volivan239 volivan239 self-assigned this Oct 28, 2022
@korifey korifey moved this to Todo in UTBot Java Oct 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp-codegen Issue is related to code generator comp-symbolic-engine Issue is related to the symbolic execution engine ctg-bug Issue is a bug lang-kotlin Issue is related to Kotlin language support
Projects
Status: Todo
Development

No branches or pull requests

1 participant