Skip to content

AssembleModel unable to analyze Kotlin constructors with not nullable reference parameters #1336

Closed

Description

@volivan239

Description

Right now we are unable to properly assemble models if there are not nullable reference parameters in constructor -- such models are instantiated through reflection right now.

To Reproduce

Launch action on class Sample from below:

data class Point(var x: Int, var y: Int)

class Sample(val y: Point) {
    fun test(): Int {
        if (y.x == 2)
            return -1
        return 0
    }
}

Expected behavior

Tests with assembled models are generated.

Actual behavior

Classes are instantiated through reflection

Visual proofs (screenshots, logs, images)

@Test
fun testKek1() {
    val s = (createInstance("nullability.Sample") as Sample)
    val point = (createInstance("nullability.Point") as Point)
    point.x = 2
    setField(s, "nullability.Sample", "y", point)
    
    val actual = kek(s)
    
    assertEquals(-1, actual)
}

Environment

Symbolic execution 100%.

Additional context

Seems like the problem is that Kotlin compiler adds to constructor of Sample instructions like INVOKESTATIC kotlin/jvm/internal/Intrinsics.checkNotNullParameter (Ljava/lang/Object;Ljava/lang/String;)V

This leads to incorrect behavior of isAppropriate and other methods in ConstructorAnalyzer

Activity

  1. moved this to Todo in UTBot Javaon Nov 9, 2022
  2. added
    lang-kotlinIssue is related to Kotlin language support
    comp-codegenIssue is related to code generator
    on Nov 9, 2022
  3. self-assigned this
    on Nov 9, 2022
  4. Repository owner moved this from Todo to Done in UTBot Javaon Nov 15, 2022
  5. added this to the 2022.12 Release milestone on Nov 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

comp-codegenIssue is related to code generatorctg-bugIssue is a buglang-kotlinIssue is related to Kotlin language support

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions