FIR: Do not add alias for variables with explicit type
This commit is contained in:
committed by
TeamCityServer
parent
5317cf3af1
commit
a0a57581ec
@@ -1,5 +1,4 @@
|
||||
// !LANGUAGE: +ProperIeee754Comparisons
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.*
|
||||
@@ -224,4 +223,4 @@ fun box(): String {
|
||||
testFloat(Float.NaN, Float.NaN, Float.NaN)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -11,10 +11,10 @@ fun foo(c: Consumer<Int>, p: Producer<Int>, u: Usual<Int>) {
|
||||
val c2: Consumer<Int> = c1
|
||||
|
||||
val p1: Producer<Any> = p
|
||||
val p2: Producer<Int> = p1
|
||||
val p2: Producer<Int> = <!INITIALIZER_TYPE_MISMATCH!>p1<!>
|
||||
|
||||
val u1: Usual<Any> = <!INITIALIZER_TYPE_MISMATCH!>u<!>
|
||||
val u2: Usual<Int> = u1
|
||||
val u2: Usual<Int> = <!INITIALIZER_TYPE_MISMATCH!>u1<!>
|
||||
}
|
||||
|
||||
//Arrays copy example
|
||||
@@ -37,4 +37,4 @@ fun f(ints: Array<Int>, any: Array<Any>, numbers: Array<Number>) {
|
||||
copy2(ints, <!ARGUMENT_TYPE_MISMATCH!>numbers<!>)
|
||||
copy3<Int>(ints, numbers)
|
||||
copy4(ints, numbers) //ok
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -6,5 +6,5 @@ fun test(a: Any?) {
|
||||
b.hashCode()
|
||||
|
||||
val c: Any? = a
|
||||
c.hashCode()
|
||||
}
|
||||
c<!UNSAFE_CALL!>.<!>hashCode()
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ enum class En { A, B, С }
|
||||
fun foo() {
|
||||
// nullable variable
|
||||
val en2: Any? = En.A
|
||||
if (<!USELESS_IS_CHECK!>en2 is En<!>) {
|
||||
if (en2 is En) {
|
||||
when (en2) {
|
||||
En.A -> {}
|
||||
En.B -> {}
|
||||
@@ -15,7 +15,7 @@ fun foo() {
|
||||
|
||||
// not nullable variable
|
||||
val en1: Any = En.A
|
||||
if (<!USELESS_IS_CHECK!>en1 is En<!>) {
|
||||
if (en1 is En) {
|
||||
when (en1) {
|
||||
En.A -> {}
|
||||
En.B -> {}
|
||||
|
||||
+1
-1
@@ -10,5 +10,5 @@ fun main() {
|
||||
val c : ListOfLists<*> = b
|
||||
val d : ArrayList<ArrayList<*>> = <!INITIALIZER_TYPE_MISMATCH!>c.x<!>
|
||||
|
||||
c.x checkType { <!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><ArrayList<out ArrayList<*>>>() }
|
||||
c.x checkType { _<ArrayList<out ArrayList<*>>>() }
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
|
||||
class A<out T, in E> {
|
||||
fun foo(x: @UnsafeVariance T) {}
|
||||
fun foo(x: @UnsafeVariance T, y: List<@UnsafeVariance T>): @UnsafeVariance E = null!!
|
||||
|
||||
fun bar(): List<@UnsafeVariance E> = null!!
|
||||
}
|
||||
|
||||
fun foo(x: A<String, Any?>, cs: CharSequence, ls: List<CharSequence>) {
|
||||
val y: A<CharSequence, String> = x
|
||||
|
||||
y.foo(<!ARGUMENT_TYPE_MISMATCH!>cs<!>)
|
||||
val s: String = <!INITIALIZER_TYPE_MISMATCH!>y.foo(<!ARGUMENT_TYPE_MISMATCH!>cs<!>, <!ARGUMENT_TYPE_MISMATCH!>ls<!>)<!>
|
||||
|
||||
val ls2: List<String> = <!INITIALIZER_TYPE_MISMATCH, TYPE_MISMATCH!>y.bar()<!>
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
|
||||
class A<out T, in E> {
|
||||
|
||||
+4
-4
@@ -32,10 +32,10 @@ fun test(s: bar.Sub<String>) {
|
||||
s.<!INVISIBLE_REFERENCE!>doSomething<!>()
|
||||
s.doSomething2()
|
||||
val s2: Super<String> = s
|
||||
s2.<!INVISIBLE_REFERENCE!>name<!>
|
||||
s2.<!INVISIBLE_REFERENCE!>name<!> = ""
|
||||
s2.name
|
||||
s2.name = ""
|
||||
s2.name2
|
||||
<!INVISIBLE_SETTER!>s2.name2<!> = ""
|
||||
s2.<!INVISIBLE_REFERENCE!>doSomething<!>()
|
||||
s2.name2 = ""
|
||||
s2.doSomething()
|
||||
s2.doSomething2()
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ fun foo(arg: Int?) {
|
||||
}
|
||||
val y: Any? = arg
|
||||
if (y != null) {
|
||||
arg.hashCode()
|
||||
arg<!UNSAFE_CALL!>.<!>hashCode()
|
||||
}
|
||||
val yy: Any?
|
||||
yy = arg
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
// SKIP_TXT
|
||||
// FILE: a/A.java
|
||||
package a;
|
||||
public interface A {
|
||||
B b();
|
||||
}
|
||||
|
||||
// FILE: a/B.java
|
||||
package a;
|
||||
public interface B {
|
||||
void bar();
|
||||
}
|
||||
|
||||
// FILE: a/AImpl.java
|
||||
package a;
|
||||
|
||||
public class AImpl implements A {
|
||||
@Override
|
||||
public BImpl b() {
|
||||
return new BImpl();
|
||||
}
|
||||
}
|
||||
|
||||
class BImpl implements B {
|
||||
@Override
|
||||
public void bar() {}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import a.A
|
||||
import a.AImpl
|
||||
|
||||
fun test1(a: A) {
|
||||
if (a is AImpl) {
|
||||
(a as A).b().bar() // OK
|
||||
a.b().<!UNRESOLVED_REFERENCE!>bar<!>()
|
||||
}
|
||||
}
|
||||
|
||||
fun test2(aImpl: AImpl) {
|
||||
val a: A = aImpl
|
||||
(a <!USELESS_CAST!>as A<!>).b().bar() // OK
|
||||
a.b().bar() // Works at FE1.0, fails at FIR
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// SKIP_TXT
|
||||
// FILE: a/A.java
|
||||
package a;
|
||||
public interface A {
|
||||
B b();
|
||||
}
|
||||
|
||||
// FILE: a/B.java
|
||||
package a;
|
||||
public interface B {
|
||||
void bar();
|
||||
}
|
||||
|
||||
// FILE: a/AImpl.java
|
||||
package a;
|
||||
|
||||
public class AImpl implements A {
|
||||
@Override
|
||||
public BImpl b() {
|
||||
return new BImpl();
|
||||
}
|
||||
}
|
||||
|
||||
class BImpl implements B {
|
||||
@Override
|
||||
public void bar() {}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
import a.A
|
||||
import a.AImpl
|
||||
|
||||
fun test1(a: A) {
|
||||
if (a is AImpl) {
|
||||
(a as A).b().bar() // OK
|
||||
<!INACCESSIBLE_TYPE!><!DEBUG_INFO_SMARTCAST!>a<!>.b()<!>.<!INVISIBLE_MEMBER!>bar<!>()
|
||||
}
|
||||
}
|
||||
|
||||
fun test2(aImpl: AImpl) {
|
||||
val a: A = aImpl
|
||||
(a <!USELESS_CAST!>as A<!>).b().bar() // OK
|
||||
a.b().bar() // Works at FE1.0, fails at FIR
|
||||
}
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ fun String.next(): String {
|
||||
|
||||
fun list(start: String) {
|
||||
var e: Any? = start
|
||||
if (<!SENSELESS_COMPARISON!>e==null<!>) return
|
||||
if (e==null) return
|
||||
while (e is String) {
|
||||
// Smart cast due to the loop condition
|
||||
if (e.length == 0)
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ fun foo(arg: Int?) {
|
||||
}
|
||||
val y: Any? = arg
|
||||
if (y != null) {
|
||||
arg.hashCode()
|
||||
arg<!UNSAFE_CALL!>.<!>hashCode()
|
||||
}
|
||||
val yy: Any?
|
||||
yy = arg
|
||||
|
||||
@@ -67,8 +67,7 @@ FILE fqName:<root> fileName:/whenSmartCastToEnum.kt
|
||||
WHEN type=kotlin.Unit origin=IF
|
||||
BRANCH
|
||||
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=<root>.En
|
||||
TYPE_OP type=<root>.En origin=IMPLICIT_CAST typeOperand=<root>.En
|
||||
GET_VAR 'val x: kotlin.Any? [val] declared in <root>.test' type=kotlin.Any? origin=null
|
||||
GET_VAR 'val x: kotlin.Any? [val] declared in <root>.test' type=kotlin.Any? origin=null
|
||||
then: BLOCK type=kotlin.Unit origin=WHEN
|
||||
VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:<root>.En [val]
|
||||
TYPE_OP type=<root>.En origin=IMPLICIT_CAST typeOperand=<root>.En
|
||||
@@ -99,8 +98,7 @@ FILE fqName:<root> fileName:/whenSmartCastToEnum.kt
|
||||
WHEN type=kotlin.Unit origin=IF
|
||||
BRANCH
|
||||
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=<root>.En
|
||||
TYPE_OP type=<root>.En origin=IMPLICIT_CAST typeOperand=<root>.En
|
||||
GET_VAR 'val y: kotlin.Any [val] declared in <root>.test' type=kotlin.Any origin=null
|
||||
GET_VAR 'val y: kotlin.Any [val] declared in <root>.test' type=kotlin.Any origin=null
|
||||
then: BLOCK type=kotlin.Unit origin=WHEN
|
||||
VAR IR_TEMPORARY_VARIABLE name:tmp_1 type:<root>.En [val]
|
||||
TYPE_OP type=<root>.En origin=IMPLICIT_CAST typeOperand=<root>.En
|
||||
|
||||
@@ -21,7 +21,7 @@ fun test() {
|
||||
var r: String = ""
|
||||
val x: Any? = En.A
|
||||
when {
|
||||
x /*as En */ is En -> { // BLOCK
|
||||
x is En -> { // BLOCK
|
||||
val tmp0_subject: En = x /*as En */
|
||||
when {
|
||||
EQEQ(arg0 = tmp0_subject, arg1 = En.A) -> { // BLOCK
|
||||
@@ -37,7 +37,7 @@ fun test() {
|
||||
}
|
||||
val y: Any = En.A
|
||||
when {
|
||||
y /*as En */ is En -> { // BLOCK
|
||||
y is En -> { // BLOCK
|
||||
val tmp1_subject: En = y /*as En */
|
||||
when {
|
||||
EQEQ(arg0 = tmp1_subject, arg1 = En.A) -> { // BLOCK
|
||||
|
||||
@@ -29,14 +29,12 @@ FILE fqName:<root> fileName:/JCTreeUser.kt
|
||||
WHEN type=kotlin.Unit origin=IF
|
||||
BRANCH
|
||||
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=<root>.JCTree.JCTypeApply
|
||||
TYPE_OP type=T of <root>.Owner origin=IMPLICIT_CAST typeOperand=T of <root>.Owner
|
||||
GET_VAR 'var tree: <root>.JCTree [var] declared in <root>.Owner.<get-foo>' type=<root>.JCTree origin=null
|
||||
GET_VAR 'var tree: <root>.JCTree [var] declared in <root>.Owner.<get-foo>' type=<root>.JCTree origin=null
|
||||
then: RETURN type=kotlin.Nothing from='public final fun <get-foo> (): kotlin.String declared in <root>.Owner'
|
||||
TYPE_OP type=@[FlexibleNullability] kotlin.String origin=IMPLICIT_NOTNULL typeOperand=@[FlexibleNullability] kotlin.String
|
||||
GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:clazz type:@[FlexibleNullability] kotlin.String? visibility:public' type=@[FlexibleNullability] kotlin.String? origin=GET_PROPERTY
|
||||
receiver: TYPE_OP type=<root>.JCTree.JCTypeApply origin=IMPLICIT_CAST typeOperand=<root>.JCTree.JCTypeApply
|
||||
TYPE_OP type=T of <root>.Owner origin=IMPLICIT_CAST typeOperand=T of <root>.Owner
|
||||
GET_VAR 'var tree: <root>.JCTree [var] declared in <root>.Owner.<get-foo>' type=<root>.JCTree origin=null
|
||||
GET_VAR 'var tree: <root>.JCTree [var] declared in <root>.Owner.<get-foo>' type=<root>.JCTree origin=null
|
||||
RETURN type=kotlin.Nothing from='public final fun <get-foo> (): kotlin.String declared in <root>.Owner'
|
||||
CONST String type=kotlin.String value=""
|
||||
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
|
||||
|
||||
@@ -13,7 +13,7 @@ class Owner<out T : JCTree> {
|
||||
get(): String {
|
||||
var tree: JCTree = <this>.<get-tree>()
|
||||
when {
|
||||
tree /*as T */ is JCTypeApply -> return tree /*as T */ /*as JCTypeApply */.#clazz /*!! @FlexibleNullability String */
|
||||
tree is JCTypeApply -> return tree /*as JCTypeApply */.#clazz /*!! @FlexibleNullability String */
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user