From 3b828ac62b6ac3b22a5d1430a8ea49be594444f7 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Mon, 14 Sep 2020 11:43:56 +0300 Subject: [PATCH] [FIR] Bad test data fixes (around captured types) --- .../tests/inference/kt28598.fir.kt | 8 ++-- .../rawTypes/rawTypeInUpperBound.fir.kt | 41 +++++++++++++++++++ .../rawTypes/rawTypeInUpperBound.kt | 4 +- 3 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawTypeInUpperBound.fir.kt diff --git a/compiler/testData/diagnostics/tests/inference/kt28598.fir.kt b/compiler/testData/diagnostics/tests/inference/kt28598.fir.kt index 288e3733bc1..ca11b71ef73 100644 --- a/compiler/testData/diagnostics/tests/inference/kt28598.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/kt28598.fir.kt @@ -15,9 +15,9 @@ fun case_1(a: MutableListg[0] if (h != null) { - h.inc() + h.inc() } } } @@ -43,9 +43,9 @@ fun case_2(a: MutableListg[0] // no SMARTCAST diagnostic if (h != null) { - h.inc() + h.inc() } } } diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawTypeInUpperBound.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawTypeInUpperBound.fir.kt new file mode 100644 index 00000000000..a66207ef414 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawTypeInUpperBound.fir.kt @@ -0,0 +1,41 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE +// FILE: A.java + +import java.util.List; + +public class A { + List getChildrenStubs() { return null; } + void consume(T x) {} + + T produce() { return null; } +} + +// FILE: B.java + +public class B { + public E foo() { return null;} + E field; +} + +// FILE: Test.java + +public class Test { + static B rawB = null; +} + +// FILE: main.kt + +fun foo(x: B<*>) { + // TODO: x.foo() now is flexible type instead of raw, because of captured type approximation + val q: MutableList = x.foo().getChildrenStubs() + + // Raw(B).field erased to A..A? + Test.rawB.field = A() + val anyA: A = Test.rawB.field + + // FIR doesn't work here, because + // field has a type of just 'A' and it's not clear why should it accept 'String' at consume + // NB: some kind of BareTypeScope should be in use here + Test.rawB.field.consume("") + val y: Any = Test.rawB.field.produce() +} diff --git a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawTypeInUpperBound.kt b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawTypeInUpperBound.kt index ade575bbaed..7bfd190c83d 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawTypeInUpperBound.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/rawTypes/rawTypeInUpperBound.kt @@ -1,4 +1,3 @@ -// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_VARIABLE // FILE: A.java @@ -34,6 +33,9 @@ fun foo(x: B<*>) { Test.rawB.field = A() val anyA: A = Test.rawB.field + // FIR doesn't work here, because + // field has a type of just 'A' and it's not clear why should it accept 'String' at consume + // NB: some kind of BareTypeScope should be in use here Test.rawB.field.consume("") val y: Any = Test.rawB.field.produce() }