// WITH_STDLIB // WORKS_WHEN_VALUE_CLASS // LANGUAGE: +ValueClasses fun underlying(a: IC): T = bar(a) { it.value as T } fun extension(a: IC): T = bar(a) { it.extensionValue() } fun dispatch(a: IC): T = bar(a) { it.dispatchValue() } fun normal(a: IC): T = bar(a) { normalValue(it) } fun bar(value: T, f: (T) -> R): R { return f(value) } fun IC.extensionValue(): T = value as T fun normalValue(ic: IC): T = ic.value as T OPTIONAL_JVM_INLINE_ANNOTATION value class IC(val value: Int) { fun dispatchValue(): T = value as T } fun box(): String { var res = underlying(IC(40)) + 2 if (res != 42) "FAIL 1: $res" res = extension(IC(40)) + 3 if (res != 43) "FAIL 2: $res" res = dispatch(IC(40)) + 4 if (res != 44) "FAIL 3: $res" res = normal(IC(40)) + 5 if (res != 45) return "FAIL 4: $res" return "OK" }