[Spec tests] Add fixed tests for expressions section, fix linkage for reference-equality-expressions section

This commit is contained in:
anastasiia.spaseeva
2019-12-26 15:11:29 +03:00
parent 9e3ecbd902
commit e0743f2268
42 changed files with 1162 additions and 106 deletions
@@ -1 +0,0 @@
java.lang.IllegalStateException: OPERATOR_MODIFIER_REQUIRED: 'operator' modifier is required on 'compareTo' in 'A' (24,17) in /2.1.kt
@@ -1,26 +0,0 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (NEGATIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, comparison-expressions -> paragraph 1 -> sentence 2
* NUMBER: 1
* DESCRIPTION: expressions, comparison-expressions -> paragraph 1 -> sentence 2
* EXCEPTION: compiletime
*/
class A(val a: Int) {
var isCompared = false
fun compareTo(other: A): Int = run {
isCompared = true
this.a - other.a
}
}
fun box() {
val a3 = A(-1)
val a4 = A(-3)
val x = (a3 > a4)
}
@@ -1,15 +1,5 @@
{
"1": {
"neg": {
"2": [
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "expressions, comparison-expressions -\u003e paragraph 1 -\u003e sentence 2",
"unexpectedBehaviour": false
}
]
},
"pos": {
"2": [
{
@@ -0,0 +1,20 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, conditional-expression -> paragraph 1 -> sentence 2
* NUMBER: 5
* DESCRIPTION: if-expression: check the correct branch is evaluating
*/
fun box() : String{
if (get(null)?: if (get(false)!!) false else get(true)!!)
return "OK"
return "NOK"
}
fun get(b: Boolean?): Boolean? = b
@@ -0,0 +1,19 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, conditional-expression -> paragraph 1 -> sentence 2
* NUMBER: 6
* DESCRIPTION: if-expression: check the correct branch is evaluating
*/
fun box() : String{
if (get(null)?: if (get(true)!!) false else get(true)!!)
return "NOK"
return "OK"
}
fun get(b: Boolean?): Boolean? = b
@@ -0,0 +1,25 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, conditional-expression -> paragraph 1 -> sentence 2
* NUMBER: 7
* DESCRIPTION: if-expression: check the correct branch is evaluating
*/
fun box(): String {
val x = if (get(null) ?: if (try {
TODO()
} catch (e: NotImplementedError) {
get(false)!!
}
) false else get(true)!!
) get(true) else false
if (x!!) return "OK"
return "NOK"
}
fun get(b: Boolean?): Boolean? = b
@@ -0,0 +1,31 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, conditional-expression -> paragraph 1 -> sentence 2
* NUMBER: 8
* DESCRIPTION: if-expression: check the correct branch is evaluating
*/
fun box(): String {
var x = 10
var flag1 = false
if (x == 10.also { x = 11 }) {
flag1 = true
}
var flag2 = false
if (x == if (true) {x = 12; 11} else 11) {
flag2 = true
}
var flag3 = false
if (12.also { x = 13 } == x) {
flag3 = true
}
if (flag1 && flag2 && !flag3)
return "OK"
return "NOK"
}
@@ -6,10 +6,32 @@
* SPEC VERSION: 0.1-218
* PLACE: expressions, conditional-expression -> paragraph 2 -> sentence 1
* NUMBER: 1
* DESCRIPTION:
* DESCRIPTION: branchless conditional expression, despite being of almost no practical use, is valid in Kotlin
*/
fun box(): String {
if (true) else;
if (true) else; ;
if (true) else ;
if (true)
else;
if (true) else
;
val x = {
if (true) else;
}
if (false) else;
if (false) else; ;
if (false) else ;
if (false)
else;
if (false) else
;
val x1 = {
if (false) else;
}
return "OK"
}
@@ -0,0 +1,36 @@
// !LANGUAGE: +NewInference
// FULL_JDK
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-220
* PLACE: expressions, conditional-expression -> paragraph 6 -> sentence 1
* NUMBER: 1
* DESCRIPTION: The type of the condition expression must be a subtype of kotlin.Boolean, otherwise it is an error
*/
// FILE: JavaClass.java
public class JavaClass{
public static <T> T id(T x) {
return null;
}
}
// FILE: KotlinClass.kt
import java.lang.IllegalStateException
fun box(): String {
val x = JavaClass.id(null) // Nothing!
return try {
val a = if (x) {
"NOK"
} else "NOK"
a
} catch (e: java.lang.IllegalStateException) {
"OK"
}
}
@@ -0,0 +1,28 @@
// FULL_JDK
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-220
* PLACE: expressions, conditional-expression -> paragraph 6 -> sentence 1
* NUMBER: 2
* DESCRIPTION: The type of the condition expression must be a subtype of kotlin.Boolean, otherwise it is an error
*/
// FILE: JavaClass.java
public class JavaClass{
public Boolean x;
}
// FILE: KotlinClass.kt
import java.lang.IllegalStateException
fun box(): String {
return try {
val a = if (JavaClass().x) { "NOK" } else "NOK"
a
} catch (e: java.lang.IllegalStateException) {
"OK"
}
}
@@ -1,7 +1,49 @@
{
"6": {
"pos": {
"1": [
{
"specVersion": "0.1-220",
"casesNumber": 0,
"description": "The type of the condition expression must be a subtype of kotlin.Boolean, otherwise it is an error",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-220",
"casesNumber": 0,
"description": "The type of the condition expression must be a subtype of kotlin.Boolean, otherwise it is an error",
"unexpectedBehaviour": false
}
]
}
},
"1": {
"pos": {
"2": [
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "if-expression: check the correct branch is evaluating",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "if-expression: check the correct branch is evaluating",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "if-expression: check the correct branch is evaluating",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "if-expression: check the correct branch is evaluating",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
@@ -48,7 +90,7 @@
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "",
"description": "branchless conditional expression, despite being of almost no practical use, is valid in Kotlin",
"unexpectedBehaviour": false
}
]
@@ -13,20 +13,27 @@
fun box(): String {
val x : Boolean? = null ?: getNull() ?: A().b ?: getTrue() ?: false
val x: Boolean? = null ?: getNull(null) ?: A().b ?: getTrue() ?: false
val s = null == getNull(null) ?: !getNullableTrue()!! || getFalse() ?: false
val k = ((getNull(null)?: getNull(null) ) ?: getNull(true)) ?: getFalse()
try {
val y = null ?: throw ExcA()
val y = null ?: throw ExcA()
} catch (e: ExcA) {
if (x == true) return "OK"
if ((x == true && !s && k!!)) return "OK"
}
return "NOK"
}
fun getTrue() = true
fun getNull(): Boolean? = null
fun getNull(b: Boolean?): Boolean? = b
class A(val b: Boolean? = null)
class ExcA() : Exception()
class ExcA() : Exception()
fun getFalse(): Boolean? { return false }
fun getNullableTrue(): Boolean? { return true }
@@ -5,7 +5,6 @@
*
* SPEC VERSION: 0.1-213
* PLACE: expressions, equality-expressions, reference-equality-expressions -> paragraph 1 -> sentence 2
* RELEVANT PLACES: expressions, built-in-types-and-their-semantics, kotlin.unit -> paragraph 1 -> sentence 1
* NUMBER: 1
* DESCRIPTION: check if two values are equal (===) by reference
*/
@@ -5,8 +5,7 @@
*
* SPEC VERSION: 0.1-213
* PLACE: expressions, equality-expressions, reference-equality-expressions -> paragraph 1 -> sentence 2
* RELEVANT PLACES: expressions, built-in-types-and-their-semantics, kotlin.unit -> paragraph 1 -> sentence 1,
* expressions, equality-expressions, reference-equality-expressions -> paragraph 3 -> sentence 3
* RELEVANT PLACES: expressions, equality-expressions, reference-equality-expressions -> paragraph 3 -> sentence 3
* expressions, equality-expressions, reference-equality-expressions -> paragraph 2 -> sentence 1
* NUMBER: 2
* DESCRIPTION: check if two values are equal (===) by reference
@@ -5,7 +5,6 @@
*
* SPEC VERSION: 0.1-213
* PLACE: expressions, equality-expressions, reference-equality-expressions -> paragraph 1 -> sentence 2
* RELEVANT PLACES: expressions, built-in-types-and-their-semantics, kotlin.unit -> paragraph 1 -> sentence 1
* NUMBER: 3
* DESCRIPTION: check if two values are non-equal (!==) by reference
*/
@@ -5,7 +5,6 @@
*
* SPEC VERSION: 0.1-213
* PLACE: expressions, equality-expressions, reference-equality-expressions -> paragraph 1 -> sentence 2
* RELEVANT PLACES: expressions, built-in-types-and-their-semantics, kotlin.unit -> paragraph 1 -> sentence 1
* NUMBER: 4
* DESCRIPTION: check if values are non-equal (!==) by reference
*/
@@ -5,7 +5,6 @@
*
* SPEC VERSION: 0.1-213
* PLACE: expressions, equality-expressions, reference-equality-expressions -> paragraph 1 -> sentence 2
* RELEVANT PLACES: expressions, built-in-types-and-their-semantics, kotlin.unit -> paragraph 1 -> sentence 1
* NUMBER: 5
* DESCRIPTION: two values are equal (===) or non-equal (!==) by reference
*/
@@ -5,7 +5,6 @@
*
* SPEC VERSION: 0.1-213
* PLACE: expressions, equality-expressions, reference-equality-expressions -> paragraph 1 -> sentence 3
* RELEVANT PLACES: expressions, built-in-types-and-their-semantics, kotlin.unit -> paragraph 1 -> sentence 1
* NUMBER: 1
* DESCRIPTION: check equallity by refference via constructor
*/
@@ -10,8 +10,13 @@
*/
// FILE: JavaClass.java
public class JavaClass{
public static Object NULL_VALUE ;
public class JavaClass {
public static Object NULL_VALUE;
public Integer x;
public static <T> T id(T x) { return null; }
}
// FILE: KotlinClass.kt
@@ -27,10 +32,31 @@ fun box(): String {
val x = null
if (null === x) {
if (x === null)
flag2 = true
flag2 = true
}
if (flag1 && flag2) return "OK"
var flag3 = false
if (null === null)
flag3 = true
var flag4 = false
val s: String? = null
if (s === JavaClass.NULL_VALUE)
if (JavaClass.NULL_VALUE === s)
flag4 = true
var flag5 = false
if (null === JavaClass().x)
if (JavaClass().x === null)
flag5 = true
var flag6 = false
if (null === JavaClass.id(null))
if (JavaClass.id(null) === null)
flag6 = true
if (flag1 && flag2 && flag3 && flag4 && flag5 &&flag6) return "OK"
else
return "NOK"
}
@@ -0,0 +1,47 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, equality-expressions, reference-equality-expressions -> paragraph 3 -> sentence 2
* NUMBER: 2
* DESCRIPTION: Any instance of the null reference null is equal by reference to any other instance of the null reference;
*/
// FILE: JavaClass.java
public class JavaClass {
public static Object NULL_VALUE;
public Integer x;
public static <T> T id(T x) { return null; }
}
// FILE: KotlinClass.kt
fun box(): String {
if (null !== JavaClass.NULL_VALUE) return "NOK"
if (JavaClass.NULL_VALUE !== null) return "NOK"
val x = null
if (null !== x) return "NOK"
if (x !== null) return "NOK"
if (null !== null) return "NOK"
val s: String? = null
if (s !== JavaClass.NULL_VALUE) return "NOK"
if (JavaClass.NULL_VALUE !== s) return "NOK"
if (getNull(true) !== getNull(false) === getNull(true) !== getNull(false) === getNull(true)) return "NOK"
if (JavaClass().x !== null) return "NOK"
if (null !== JavaClass().x ) return "NOK"
if (JavaClass.id(null) !== null) return "NOK"
if (null !== JavaClass.id(null) ) return "NOK"
return "OK"
}
fun getNull(x: Boolean): Any? = if (x) null else ""
@@ -52,7 +52,22 @@
},
"3": {
"pos": {
"3": [
{
"specVersion": "0.1-213",
"casesNumber": 0,
"description": "check if two values are equal (\u003d\u003d\u003d) by reference",
"path": "compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/reference-equality-expressions/p-1/pos/2.2.kt",
"unexpectedBehaviour": false
}
],
"2": [
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "Any instance of the null reference null is equal by reference to any other instance of the null reference;",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
@@ -16,18 +16,21 @@ fun box(): String {
val x = A(false)
val y = A(false)
if (x == y) {
if ((x == y) == checkEqualls(x, y)) {
if (x.isEqualsCalled && !y.isEqualsCalled)
return "OK"
}
return "NOK"
}
fun checkEqualls(A: Any?, B: Any?): Boolean {
return (A as? Any)?.equals(B) ?: (B === null)
}
data class A(val a: Boolean) {
var isEqualsCalled = false
override fun equals(anObject: Any?): Boolean {
override operator fun equals(anObject: Any?): Boolean {
isEqualsCalled = true
if (this === anObject) {
return true
@@ -0,0 +1,44 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, equality-expressions, value-equality-expressions -> paragraph 2 -> sentence 1
* RELEVANT PLACES: expressions, equality-expressions, value-equality-expressions -> paragraph 3 -> sentence 1
* NUMBER: 2
* DESCRIPTION: check value-equality-expression
*/
//A == B is exactly the same as (A as? Any)?.equals(B) ?: (B === null) where equals is the method of kotlin.Any;
fun box(): String {
val x = A(false)
val y = A(true)
if ((x == y) == checkEqualls(x, y)) {
if (x.isEqualsCalled)
return "OK"
}
return "NOK"
}
fun checkEqualls(A: Any?, B: Any?): Boolean {
return (A as? Any)?.equals(B) ?: (B === null)
}
data class A(val a: Boolean) {
var isEqualsCalled = false
override operator fun equals(anObject: Any?): Boolean {
isEqualsCalled = true
if (this === anObject) {
return true
}
if (anObject is A) {
if (anObject.a == a)
return true
}
return false
}
}
@@ -0,0 +1,44 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, equality-expressions, value-equality-expressions -> paragraph 2 -> sentence 1
* RELEVANT PLACES: expressions, equality-expressions, value-equality-expressions -> paragraph 3 -> sentence 1
* NUMBER: 3
* DESCRIPTION: check value-equality-expression
*/
//A == B is exactly the same as (A as? Any)?.equals(B) ?: (B === null) where equals is the method of kotlin.Any;
fun box(): String {
val x = A(false)
val y = null
if ((x == y) == checkEqualls(x, y)) {
if (x.isEqualsCalled)
return "OK"
}
return "NOK"
}
fun checkEqualls(A: Any?, B: Any?): Boolean {
return (A as? Any)?.equals(B) ?: (B === null)
}
data class A(val a: Boolean) {
var isEqualsCalled = false
override operator fun equals(anObject: Any?): Boolean {
isEqualsCalled = true
if (this === anObject) {
return true
}
if (anObject is A) {
if (anObject.a == a)
return true
}
return false
}
}
@@ -0,0 +1,43 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, equality-expressions, value-equality-expressions -> paragraph 2 -> sentence 1
* RELEVANT PLACES: expressions, equality-expressions, value-equality-expressions -> paragraph 3 -> sentence 1
* NUMBER: 4
* DESCRIPTION: check value-equality-expression
*/
//A == B is exactly the same as (A as? Any)?.equals(B) ?: (B === null) where equals is the method of kotlin.Any;
fun box(): String {
val x = null
val y = null
if ((x == y) == checkEqualls(x, y)) {
return "OK"
}
return "NOK"
}
fun checkEqualls(A: Any?, B: Any?): Boolean {
return (A as? Any)?.equals(B) ?: (B === null)
}
data class A(val a: Boolean) {
var isEqualsCalled = false
override operator fun equals(anObject: Any?): Boolean {
isEqualsCalled = true
if (this === anObject) {
return true
}
if (anObject is A) {
if (anObject.a == a)
return true
}
return false
}
}
@@ -0,0 +1,44 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, equality-expressions, value-equality-expressions -> paragraph 2 -> sentence 1
* RELEVANT PLACES: expressions, equality-expressions, value-equality-expressions -> paragraph 3 -> sentence 1
* NUMBER: 5
* DESCRIPTION: check value-equality-expression
*/
//A == B is exactly the same as (A as? Any)?.equals(B) ?: (B === null) where equals is the method of kotlin.Any;
fun box(): String {
val x: A = A(false)
val y: Any = ""
if ((x == y) == checkEqualls(x, y)) {
if (x.isEqualsCalled)
return "OK"
}
return "NOK"
}
fun checkEqualls(A: Any?, B: Any?): Boolean {
return (A as? Any)?.equals(B) ?: (B === null)
}
data class A(val a: Boolean) {
var isEqualsCalled = false
override operator fun equals(anObject: Any?): Boolean {
isEqualsCalled = true
if (this === anObject) {
return true
}
if (anObject is A) {
if (anObject.a == a)
return true
}
return false
}
}
@@ -1,10 +1,10 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (NEGATIVE)
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, equality-expressions, value-equality-expressions -> paragraph 2 -> sentence 1
* PLACE: expressions, equality-expressions, value-equality-expressions -> paragraph 2 -> sentence 2
* NUMBER: 1
* DESCRIPTION: check value-equality-expression
*/
@@ -12,22 +12,27 @@
//A != B is exactly the same as !((A as? Any)?.equals(B) ?: (B === null)) where equals is the method of kotlin.Any.
fun box():String{
val x = A(true)
val y = A(false)
if (x != y) {
if ((x != y) == checkNotEquals(x, y)) {
if (x.isEqualsCalled && !y.isEqualsCalled)
return "OK"
}
return "NOK"
}
fun checkNotEquals(A: Any?, B: Any?): Boolean {
return !((A as? Any)?.equals(B) ?: (B === null))
}
data class A(val a: Boolean) {
var isEqualsCalled = false
override fun equals(anObject: Any?): Boolean {
override operator fun equals(anObject: Any?): Boolean {
isEqualsCalled = true
if (this === anObject) {
return true
@@ -0,0 +1,45 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, equality-expressions, value-equality-expressions -> paragraph 2 -> sentence 2
* NUMBER: 2
* DESCRIPTION: check value-equality-expression
*/
//A != B is exactly the same as !((A as? Any)?.equals(B) ?: (B === null)) where equals is the method of kotlin.Any.
fun box():String{
val x = A(true)
val y = A(true)
if ((x != y) == checkNotEquals(x, y)) {
if (x.isEqualsCalled && !y.isEqualsCalled)
return "OK"
}
return "NOK"
}
fun checkNotEquals(A: Any?, B: Any?): Boolean {
return !((A as? Any)?.equals(B) ?: (B === null))
}
data class A(val a: Boolean) {
var isEqualsCalled = false
override operator fun equals(anObject: Any?): Boolean {
isEqualsCalled = true
if (this === anObject) {
return true
}
if (anObject is A) {
if (anObject.a == a)
return true
}
return false
}
}
@@ -0,0 +1,44 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, equality-expressions, value-equality-expressions -> paragraph 2 -> sentence 2
* NUMBER: 3
* DESCRIPTION: check value-equality-expression
*/
//A != B is exactly the same as !((A as? Any)?.equals(B) ?: (B === null)) where equals is the method of kotlin.Any.
fun box():String{
val x = null
val y = A(true)
if ((x != y) == checkNotEquals(x, y)) {
return "OK"
}
return "NOK"
}
fun checkNotEquals(A: Any?, B: Any?): Boolean {
return !((A as? Any)?.equals(B) ?: (B === null))
}
data class A(val a: Boolean) {
var isEqualsCalled = false
override operator fun equals(anObject: Any?): Boolean {
isEqualsCalled = true
if (this === anObject) {
return true
}
if (anObject is A) {
if (anObject.a == a)
return true
}
return false
}
}
@@ -0,0 +1,44 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, equality-expressions, value-equality-expressions -> paragraph 2 -> sentence 2
* NUMBER: 4
* DESCRIPTION: check value-equality-expression
*/
//A != B is exactly the same as !((A as? Any)?.equals(B) ?: (B === null)) where equals is the method of kotlin.Any.
fun box():String{
val x = null
val y = null
if ((x != y) == checkNotEquals(x, y)) {
return "OK"
}
return "NOK"
}
fun checkNotEquals(A: Any?, B: Any?): Boolean {
return !((A as? Any)?.equals(B) ?: (B === null))
}
data class A(val a: Boolean) {
var isEqualsCalled = false
override operator fun equals(anObject: Any?): Boolean {
isEqualsCalled = true
if (this === anObject) {
return true
}
if (anObject is A) {
if (anObject.a == a)
return true
}
return false
}
}
@@ -0,0 +1,45 @@
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-218
* PLACE: expressions, equality-expressions, value-equality-expressions -> paragraph 2 -> sentence 2
* NUMBER: 5
* DESCRIPTION: check value-equality-expression
*/
//A != B is exactly the same as !((A as? Any)?.equals(B) ?: (B === null)) where equals is the method of kotlin.Any.
fun box():String{
val x = A(true)
val y : Any = ""
if ((x != y) == checkNotEquals(x, y)) {
if (x.isEqualsCalled)
return "OK"
}
return "NOK"
}
fun checkNotEquals(A: Any?, B: Any?): Boolean {
return !((A as? Any)?.equals(B) ?: (B === null))
}
data class A(val a: Boolean) {
var isEqualsCalled = false
override operator fun equals(anObject: Any?): Boolean {
isEqualsCalled = true
if (this === anObject) {
return true
}
if (anObject is A) {
if (anObject.a == a)
return true
}
return false
}
}
@@ -1,17 +1,63 @@
{
"2": {
"neg": {
"1": [
"pos": {
"2": [
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "check value-equality-expression",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "check value-equality-expression",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "check value-equality-expression",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "check value-equality-expression",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "check value-equality-expression",
"unexpectedBehaviour": false
}
]
},
"pos": {
],
"1": [
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "check value-equality-expression",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "check value-equality-expression",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "check value-equality-expression",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "check value-equality-expression",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
@@ -24,6 +70,34 @@
"3": {
"pos": {
"1": [
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "check value-equality-expression",
"path": "compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/value-equality-expressions/p-2/pos/1.2.kt",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "check value-equality-expression",
"path": "compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/value-equality-expressions/p-2/pos/1.3.kt",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "check value-equality-expression",
"path": "compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/value-equality-expressions/p-2/pos/1.4.kt",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
"description": "check value-equality-expression",
"path": "compiler/tests-spec/testData/codegen/box/linked/expressions/equality-expressions/value-equality-expressions/p-2/pos/1.5.kt",
"unexpectedBehaviour": false
},
{
"specVersion": "0.1-218",
"casesNumber": 0,
@@ -0,0 +1 @@
java.lang.IllegalStateException: TYPE_MISMATCH: Type mismatch: inferred type is Nothing? but Boolean was expected (7,21) in /KotlinClass.kt
@@ -0,0 +1,34 @@
// FULL_JDK
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX NOT LINKED SPEC TEST (NEGATIVE)
*
* SECTIONS: flexibility
* NUMBER: 1
* DESCRIPTION: check Nothing flexibillity
* EXCEPTION: compiletime
* ISSUES: KT-35700
*/
// FILE: JavaClass.java
public class JavaClass{
public static <T> T id(T x) {
return null;
}
}
// FILE: KotlinClass.kt
fun box(): String {
val x = JavaClass.id(null) // Nothing!
return try {
val a = if (x) {
"NOK"
} else "NOK"
a
} catch (e: java.lang.IllegalStateException) {
"OK"
}
}
@@ -0,0 +1 @@
java.lang.IllegalStateException: TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH: Type inference failed. Expected type mismatch: inferred type is Test<Nothing?> but Base<T> was expected (7,38) in /KotlinClass.kt
@@ -0,0 +1,36 @@
// FULL_JDK
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX NOT LINKED SPEC TEST (NEGATIVE)
*
* SECTIONS: flexibility
* NUMBER: 2
* DESCRIPTION: check Nothing flexibillity
* EXCEPTION: compiletime
* ISSUES: KT-35700
*/
// FILE: Test.java
public class Test<T> extends Base<T> {
public Test (T arg) {
super(arg);
}
}
// FILE: KotlinClass.kt
open class Base<out T>(val prop: T)
class Inheritor <T : Any> {
companion object {
fun <T> default(): Base<T> = Test(null)
}
}
fun box() {
val v: Base<String> = Inheritor.default()
println(v.prop.length)
}
@@ -0,0 +1,34 @@
// !LANGUAGE: +NewInference
// FULL_JDK
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX NOT LINKED SPEC TEST (POSITIVE)
*
* SECTIONS: flexibility
* NUMBER: 1
* DESCRIPTION: check Nothing flexibillity
* ISSUES: KT-35700
*/
// FILE: JavaClass.java
public class JavaClass{
public static <T> T id(T x) {
return null;
}
}
// FILE: KotlinClass.kt
fun box(): String {
val x = JavaClass.id(null) // Nothing!
return try {
val a = if (x) {
"NOK"
} else "NOK"
a
} catch (e: IllegalStateException) {
"OK"
}
}
@@ -0,0 +1,42 @@
// !LANGUAGE: +NewInference
// FULL_JDK
// WITH_RUNTIME
/*
* KOTLIN CODEGEN BOX NOT LINKED SPEC TEST (POSITIVE)
*
* SECTIONS: flexibility
* NUMBER: 2
* DESCRIPTION: check Nothing flexibillity
* ISSUES: KT-35700
*/
// FILE: Test.java
public class Test<T> extends Base<T> {
public Test (T arg) {
super(arg);
}
}
// FILE: KotlinClass.kt
open class Base<out T>(val prop: T)
class Inheritor <T : Any> {
companion object {
fun <T> default(): Base<T> = Test(null)
}
}
fun box() : String{
val v: Base<String> = Inheritor.default()
try {
println(v.prop.length)
}catch (e: Exception ){
return "OK"
}
return "NOK"
}