[FIR] Introduce TYPE_ARGUMENTS_NOT_ALLOWED & some other type errors

This commit introduces several different things, in particular:
- check type arguments in expressions
- new TypeArgumentList node to deal with diagnostic source
- ConeDiagnostic was moved to fir:cones
- ConeIntermediateDiagnostic to use in inference (?) without reporting
- detailed diagnostics on error type
This commit is contained in:
Mikhail Glukhikh
2020-07-22 10:29:59 +03:00
parent c744dfba9c
commit 0804c6a0f3
196 changed files with 774 additions and 484 deletions
@@ -22,6 +22,7 @@ interface B {
<!REDUNDANT_MODALITY_MODIFIER!>abstract<!> var bar: Unit
<!REDUNDANT_MODALITY_MODIFIER!>abstract<!> fun foo()
}
interface Foo
expect abstract class AbstractClass : Foo {
abstract override fun foo()
@@ -36,7 +36,9 @@ FILE: RedundantModalityModifierChecker.kt
public abstract fun foo(): R|kotlin/Unit|
}
public abstract expect class AbstractClass : R|ERROR CLASS: Symbol not found, for `Foo`| {
public abstract interface Foo : R|kotlin/Any| {
}
public abstract expect class AbstractClass : R|Foo| {
public expect constructor(): R|AbstractClass| {
super<R|kotlin/Any|>()
}
@@ -5,7 +5,7 @@ interface A {
val b: B?
}
class C(a: A, b: b) {
class C(a: A, b: B) {
init {
val c = a.b?.let {
C(a, it)
@@ -7,7 +7,7 @@ FILE: initBlockAndInPlaceLambda.kt
}
public final class C : R|kotlin/Any| {
public constructor(a: R|A|, b: R|ERROR CLASS: Symbol not found, for `b`|): R|C| {
public constructor(a: R|A|, b: R|B|): R|C| {
super<R|kotlin/Any|>()
}
@@ -1,3 +1,4 @@
// FULL_JDK
// FILE: util/HashMap.java
package util;
@@ -1,7 +1,7 @@
FILE: LinkedList.kt
public final class LinkedList<T> : R|ERROR CLASS: Symbol not found, for `java.util.LinkedList<R|T|>`| {
public final class LinkedList<T> : R|java/util/LinkedList<T>| {
public constructor<T>(): R|foo/LinkedList<T>| {
super<R|ERROR CLASS: Symbol not found, for `java.util.LinkedList<R|T|>`|>()
super<R|java/util/LinkedList<T>|>()
}
}
@@ -13,9 +13,9 @@ FILE: HashSet.kt
}
FILE: main.kt
public final class LinkedHashMap<K, V> : R|ERROR CLASS: Symbol not found, for `java.util.LinkedHashMap<R|K|, R|V|>`| {
public final class LinkedHashMap<K, V> : R|java/util/LinkedHashMap<K, V>| {
public constructor<K, V>(): R|foo/LinkedHashMap<K, V>| {
super<R|ERROR CLASS: Symbol not found, for `java.util.LinkedHashMap<R|K|, R|V|>`|>()
super<R|java/util/LinkedHashMap<K, V>|>()
}
}
@@ -1,7 +1,7 @@
fun foo() {
<!LOCAL_ANNOTATION_CLASS_ERROR!>annotation class Ann<!>
@Anno class Local {
@Ann class Local {
// There should also be NESTED_CLASS_NOT_ALLOWED report here.
<!LOCAL_ANNOTATION_CLASS_ERROR!>annotation class Nested<!>
}
@@ -7,7 +7,7 @@ FILE: localAnnotationClass.kt
}
@R|ERROR CLASS: Symbol not found, for `Anno`|() local final class Local : R|kotlin/Any| {
@R|Ann|() local final class Local : R|kotlin/Any| {
public constructor(): R|Local| {
super<R|kotlin/Any|>()
}
@@ -0,0 +1,34 @@
package rest
abstract class Foo<T> {
abstract val x: <!TYPE_ARGUMENTS_NOT_ALLOWED, TYPE_ARGUMENTS_NOT_ALLOWED!>T<Int><!>
abstract fun foo(): <!TYPE_ARGUMENTS_NOT_ALLOWED!>T<String><!>
}
fun <T> foo() {
bar<<!TYPE_ARGUMENTS_NOT_ALLOWED, UPPER_BOUND_VIOLATED!>T<Int><!>>()
bar<List<List<<!TYPE_ARGUMENTS_NOT_ALLOWED, UPPER_BOUND_VIOLATED!>T<Boolean><!>>>>()
}
fun <T> bar() {}
object Best {
}
val a = <!TYPE_ARGUMENTS_NOT_ALLOWED!>rest<Int><!>.<!UNRESOLVED_REFERENCE!>MyClass<!><String>
val b = Best.<!UNRESOLVED_REFERENCE!>MyClass<!><String>
class B<E>
class C<F<!SYNTAX!><<!><!SYNTAX!>Boolean<!><!SYNTAX!>><!><!SYNTAX!>><!> <!SYNTAX!>:<!> <!SYNTAX!>B<!><!SYNTAX!><<!><!SYNTAX!>F<!><!SYNTAX!><<!><!SYNTAX!>Boolean<!><!SYNTAX!>><!><!SYNTAX!>><!><!SYNTAX!>(<!><!SYNTAX!>)<!>
fun <G> gest() {}
fun <T> fest() {
val b: List<<!TYPE_ARGUMENTS_NOT_ALLOWED!>T<Double><!>>
gest<<!TYPE_ARGUMENTS_NOT_ALLOWED, UPPER_BOUND_VIOLATED!>T<Char><!>>()
gest<T>()
val c: List<List<List<<!TYPE_ARGUMENTS_NOT_ALLOWED!>T<String><!>>>>
gest<List<List<<!TYPE_ARGUMENTS_NOT_ALLOWED, UPPER_BOUND_VIOLATED!>T<Boolean><!>>>>()
}
@@ -0,0 +1,49 @@
FILE: typeArgumentsNotAllowed.kt
public abstract class Foo<T> : R|kotlin/Any| {
public constructor<T>(): R|rest/Foo<T>| {
super<R|kotlin/Any|>()
}
public abstract val x: <ERROR TYPE REF: Type arguments not allowed>
public get(): <ERROR TYPE REF: Type arguments not allowed>
public abstract fun foo(): <ERROR TYPE REF: Type arguments not allowed>
}
public final fun <T> foo(): R|kotlin/Unit| {
R|rest/bar|<<ERROR TYPE REF: Type arguments not allowed>>()
R|rest/bar|<<ERROR TYPE REF: Type arguments not allowed>>()
}
public final fun <T> bar(): R|kotlin/Unit| {
}
public final object Best : R|kotlin/Any| {
private constructor(): R|rest/Best| {
super<R|kotlin/Any|>()
}
}
public final val a: <ERROR TYPE REF: Unresolved name: MyClass> = Q|rest|.<Unresolved name: MyClass>#
public get(): <ERROR TYPE REF: Unresolved name: MyClass>
public final val b: <ERROR TYPE REF: Unresolved name: MyClass> = Q|rest/Best|.<Unresolved name: MyClass>#
public get(): <ERROR TYPE REF: Unresolved name: MyClass>
public final class B<E> : R|kotlin/Any| {
public constructor<E>(): R|rest/B<E>| {
super<R|kotlin/Any|>()
}
}
public final class C<F> : R|kotlin/Any| {
public constructor<F>(): R|rest/C<F>| {
super<R|kotlin/Any|>()
}
}
public final fun <G> gest(): R|kotlin/Unit| {
}
public final fun <T> fest(): R|kotlin/Unit| {
lval b: <ERROR TYPE REF: Type arguments not allowed>
R|rest/gest|<<ERROR TYPE REF: Type arguments not allowed>>()
R|rest/gest|<R|T|>()
lval c: <ERROR TYPE REF: Type arguments not allowed>
R|rest/gest|<<ERROR TYPE REF: Type arguments not allowed>>()
}
@@ -14,8 +14,8 @@ fun test() {
val b1 = B<<!UPPER_BOUND_VIOLATED!>Int<!>>()
val b2 = B<C>()
val b3 = B<<!UPPER_BOUND_VIOLATED!>Any?<!>>()
val b4 = B<UnexistingType>()
val b5 = B<<!UPPER_BOUND_VIOLATED!>B<UnexistingType><!>>()
val b4 = B<<!OTHER_ERROR, UPPER_BOUND_VIOLATED!>UnexistingType<!>>()
val b5 = B<<!OTHER_ERROR, UPPER_BOUND_VIOLATED!>B<UnexistingType><!>>()
fest<<!UPPER_BOUND_VIOLATED!>Boolean<!>>()
fest<C>()
fest<HHH>()
@@ -22,8 +22,8 @@ FILE: upperBoundViolated.kt
lval b1: R|B<kotlin/Int>| = R|/B.B|<R|kotlin/Int|>()
lval b2: R|B<C>| = R|/B.B|<R|C|>()
lval b3: R|B<kotlin/Any?>| = R|/B.B|<R|kotlin/Any?|>()
lval b4: R|B<A>| = R|/B.B|<R|A|>()
lval b5: R|B<B<ERROR CLASS: Symbol not found, for `UnexistingType`>>| = R|/B.B|<R|B<ERROR CLASS: Symbol not found, for `UnexistingType`>|>()
lval b4: R|B<A>| = R|/B.B|<<ERROR TYPE REF: Symbol not found, for `UnexistingType`>>()
lval b5: R|B<A>| = R|/B.B|<<ERROR TYPE REF: Symbol not found, for `UnexistingType`>>()
R|/fest|<R|kotlin/Boolean|>()
R|/fest|<R|C|>()
R|/fest|<R|C|>()
@@ -1,5 +1,15 @@
package org.jetbrains.kotlin.codegen.range.inExpression
interface ExpressionCodegen
interface KtSimpleNameExpression
interface InExpressionGenerator
interface StackValue
open class BranchedValue
interface Type
interface KotlinType
interface Label
interface InstructionAdapter
class CallBasedInExpressionGenerator(
val codegen: ExpressionCodegen,
operatorReference: KtSimpleNameExpression
@@ -8,10 +18,10 @@ class CallBasedInExpressionGenerator(
private val isInverted = operatorReference.<!UNRESOLVED_REFERENCE!>getReferencedNameElementType<!>() == <!UNRESOLVED_REFERENCE!>KtTokens<!>.<!UNRESOLVED_REFERENCE!>NOT_IN<!>
override fun generate(argument: StackValue): BranchedValue =
gen(argument).<!INAPPLICABLE_CANDIDATE!>let<!> { if (isInverted) <!UNRESOLVED_REFERENCE!>Invert<!>(it) else it }
gen(argument).let { if (isInverted) <!UNRESOLVED_REFERENCE!>Invert<!>(it) else it }
private fun gen(argument: StackValue): BranchedValue =
object : BranchedValue(argument, null, argument.<!UNRESOLVED_REFERENCE!>type<!>, <!UNRESOLVED_REFERENCE!>Opcodes<!>.<!UNRESOLVED_REFERENCE!>IFEQ<!>) {
object : <!INAPPLICABLE_CANDIDATE!>BranchedValue<!>(argument, null, argument.<!UNRESOLVED_REFERENCE!>type<!>, <!UNRESOLVED_REFERENCE!>Opcodes<!>.<!UNRESOLVED_REFERENCE!>IFEQ<!>) {
override fun putSelector(type: Type, kotlinType: KotlinType?, v: InstructionAdapter) {
invokeFunction(v)
<!UNRESOLVED_REFERENCE!>coerceTo<!>(type, kotlinType, v)
@@ -1,11 +1,33 @@
FILE: CallBasedInExpressionGenerator.kt
public final class CallBasedInExpressionGenerator : R|ERROR CLASS: Symbol not found, for `InExpressionGenerator`| {
public constructor(codegen: R|ERROR CLASS: Symbol not found, for `ExpressionCodegen`|, operatorReference: R|ERROR CLASS: Symbol not found, for `KtSimpleNameExpression`|): R|org/jetbrains/kotlin/codegen/range/inExpression/CallBasedInExpressionGenerator| {
public abstract interface ExpressionCodegen : R|kotlin/Any| {
}
public abstract interface KtSimpleNameExpression : R|kotlin/Any| {
}
public abstract interface InExpressionGenerator : R|kotlin/Any| {
}
public abstract interface StackValue : R|kotlin/Any| {
}
public open class BranchedValue : R|kotlin/Any| {
public constructor(): R|org/jetbrains/kotlin/codegen/range/inExpression/BranchedValue| {
super<R|kotlin/Any|>()
}
public final val codegen: R|ERROR CLASS: Symbol not found, for `ExpressionCodegen`| = R|<local>/codegen|
public get(): R|ERROR CLASS: Symbol not found, for `ExpressionCodegen`|
}
public abstract interface Type : R|kotlin/Any| {
}
public abstract interface KotlinType : R|kotlin/Any| {
}
public abstract interface Label : R|kotlin/Any| {
}
public abstract interface InstructionAdapter : R|kotlin/Any| {
}
public final class CallBasedInExpressionGenerator : R|org/jetbrains/kotlin/codegen/range/inExpression/InExpressionGenerator| {
public constructor(codegen: R|org/jetbrains/kotlin/codegen/range/inExpression/ExpressionCodegen|, operatorReference: R|org/jetbrains/kotlin/codegen/range/inExpression/KtSimpleNameExpression|): R|org/jetbrains/kotlin/codegen/range/inExpression/CallBasedInExpressionGenerator| {
super<R|kotlin/Any|>()
}
public final val codegen: R|org/jetbrains/kotlin/codegen/range/inExpression/ExpressionCodegen| = R|<local>/codegen|
public get(): R|org/jetbrains/kotlin/codegen/range/inExpression/ExpressionCodegen|
private final val resolvedCall: <ERROR TYPE REF: Unresolved name: getResolvedCallWithAssert> = R|<local>/operatorReference|.<Unresolved name: getResolvedCallWithAssert>#(R|<local>/codegen|.<Unresolved name: bindingContext>#)
private get(): <ERROR TYPE REF: Unresolved name: getResolvedCallWithAssert>
@@ -13,8 +35,8 @@ FILE: CallBasedInExpressionGenerator.kt
private final val isInverted: R|kotlin/Boolean| = ==(R|<local>/operatorReference|.<Unresolved name: getReferencedNameElementType>#(), <Unresolved name: KtTokens>#.<Unresolved name: NOT_IN>#)
private get(): R|kotlin/Boolean|
public final override fun generate(argument: R|ERROR CLASS: Symbol not found, for `StackValue`|): R|ERROR CLASS: Symbol not found, for `BranchedValue`| {
^generate this@R|org/jetbrains/kotlin/codegen/range/inExpression/CallBasedInExpressionGenerator|.R|org/jetbrains/kotlin/codegen/range/inExpression/CallBasedInExpressionGenerator.gen|(R|<local>/argument|).<Inapplicable(WRONG_RECEIVER): kotlin/let>#<R|kotlin/Any?|, R|kotlin/Nothing|>(<L> = let@fun <anonymous>(it: R|kotlin/Any?|): <ERROR TYPE REF: Can't resolve when expression> <kind=EXACTLY_ONCE> {
public final override fun generate(argument: R|org/jetbrains/kotlin/codegen/range/inExpression/StackValue|): R|org/jetbrains/kotlin/codegen/range/inExpression/BranchedValue| {
^generate this@R|org/jetbrains/kotlin/codegen/range/inExpression/CallBasedInExpressionGenerator|.R|org/jetbrains/kotlin/codegen/range/inExpression/CallBasedInExpressionGenerator.gen|(R|<local>/argument|).R|kotlin/let|<R|org/jetbrains/kotlin/codegen/range/inExpression/BranchedValue|, R|org/jetbrains/kotlin/codegen/range/inExpression/BranchedValue|>(<L> = let@fun <anonymous>(it: R|org/jetbrains/kotlin/codegen/range/inExpression/BranchedValue|): R|org/jetbrains/kotlin/codegen/range/inExpression/BranchedValue| <kind=EXACTLY_ONCE> {
^ when () {
this@R|org/jetbrains/kotlin/codegen/range/inExpression/CallBasedInExpressionGenerator|.R|org/jetbrains/kotlin/codegen/range/inExpression/CallBasedInExpressionGenerator.isInverted| -> {
<Unresolved name: Invert>#(R|<local>/it|)
@@ -28,18 +50,18 @@ FILE: CallBasedInExpressionGenerator.kt
)
}
private final fun gen(argument: R|ERROR CLASS: Symbol not found, for `StackValue`|): R|ERROR CLASS: Symbol not found, for `BranchedValue`| {
^gen object : R|ERROR CLASS: Symbol not found, for `BranchedValue`| {
private final fun gen(argument: R|org/jetbrains/kotlin/codegen/range/inExpression/StackValue|): R|org/jetbrains/kotlin/codegen/range/inExpression/BranchedValue| {
^gen object : R|org/jetbrains/kotlin/codegen/range/inExpression/BranchedValue| {
private constructor(): R|<anonymous>| {
super<R|ERROR CLASS: Symbol not found, for `BranchedValue`|>(R|<local>/argument|, Null(null), R|<local>/argument|.<Unresolved name: type>#, <Unresolved name: Opcodes>#.<Unresolved name: IFEQ>#)
super<R|org/jetbrains/kotlin/codegen/range/inExpression/BranchedValue|>(R|<local>/argument|, Null(null), R|<local>/argument|.<Unresolved name: type>#, <Unresolved name: Opcodes>#.<Unresolved name: IFEQ>#)
}
public final override fun putSelector(type: R|ERROR CLASS: Symbol not found, for `Type`|, kotlinType: R|ERROR CLASS: Symbol not found, for `KotlinType?`|, v: R|ERROR CLASS: Symbol not found, for `InstructionAdapter`|): R|kotlin/Unit| {
public final override fun putSelector(type: R|org/jetbrains/kotlin/codegen/range/inExpression/Type|, kotlinType: R|org/jetbrains/kotlin/codegen/range/inExpression/KotlinType?|, v: R|org/jetbrains/kotlin/codegen/range/inExpression/InstructionAdapter|): R|kotlin/Unit| {
this@R|/<anonymous>|.R|/<anonymous>.invokeFunction|(R|<local>/v|)
<Unresolved name: coerceTo>#(R|<local>/type|, R|<local>/kotlinType|, R|<local>/v|)
}
public final override fun condJump(jumpLabel: R|ERROR CLASS: Symbol not found, for `Label`|, v: R|ERROR CLASS: Symbol not found, for `InstructionAdapter`|, jumpIfFalse: R|kotlin/Boolean|): R|kotlin/Unit| {
public final override fun condJump(jumpLabel: R|org/jetbrains/kotlin/codegen/range/inExpression/Label|, v: R|org/jetbrains/kotlin/codegen/range/inExpression/InstructionAdapter|, jumpIfFalse: R|kotlin/Boolean|): R|kotlin/Unit| {
this@R|/<anonymous>|.R|/<anonymous>.invokeFunction|(R|<local>/v|)
R|<local>/v|.<Unresolved name: visitJumpInsn>#(when () {
R|<local>/jumpIfFalse| -> {
@@ -52,7 +74,7 @@ FILE: CallBasedInExpressionGenerator.kt
, R|<local>/jumpLabel|)
}
private final fun invokeFunction(v: R|ERROR CLASS: Symbol not found, for `InstructionAdapter`|): R|kotlin/Unit| {
private final fun invokeFunction(v: R|org/jetbrains/kotlin/codegen/range/inExpression/InstructionAdapter|): R|kotlin/Unit| {
lval result: <ERROR TYPE REF: Unresolved name: invokeFunction> = this@R|org/jetbrains/kotlin/codegen/range/inExpression/CallBasedInExpressionGenerator|.R|org/jetbrains/kotlin/codegen/range/inExpression/CallBasedInExpressionGenerator.codegen|.<Unresolved name: invokeFunction>#(this@R|org/jetbrains/kotlin/codegen/range/inExpression/CallBasedInExpressionGenerator|.R|org/jetbrains/kotlin/codegen/range/inExpression/CallBasedInExpressionGenerator.resolvedCall|.<Unresolved name: call>#, this@R|org/jetbrains/kotlin/codegen/range/inExpression/CallBasedInExpressionGenerator|.R|org/jetbrains/kotlin/codegen/range/inExpression/CallBasedInExpressionGenerator.resolvedCall|, <Unresolved name: none>#())
R|<local>/result|.<Unresolved name: put>#(R|<local>/result|.<Unresolved name: type>#, R|<local>/result|.<Unresolved name: kotlinType>#, R|<local>/v|)
}
@@ -1,5 +1,5 @@
FILE: fakeRecursiveSupertype.kt
public final class My : R|ERROR CLASS: Loop in supertype: /My -> /My| {
public final class My : <ERROR TYPE REF: Loop in supertype: /My -> /My> {
public constructor(): R|My| {
super<R|My|>()
}
@@ -11,7 +11,7 @@ FILE: fakeRecursiveSupertype.kt
}
}
public final class His : R|ERROR CLASS: Loop in supertype: /His -> /Your| {
public final class His : <ERROR TYPE REF: Loop in supertype: /His -> /Your> {
public constructor(): R|His| {
super<R|Your|>()
}
@@ -1,5 +1,5 @@
import incorrect.directory.Your
typealias My = incorrect.directory.My
typealias My = <!OTHER_ERROR!>incorrect.directory.My<!>
typealias Your = <!OTHER_ERROR!>Your<!>
@@ -1,3 +1,3 @@
FILE: fakeRecursiveTypealias.kt
public final typealias My = R|ERROR CLASS: Symbol not found, for `incorrect.directory.My`|
public final typealias Your = R|ERROR CLASS: Loop in supertype: /Your -> /Your|
public final typealias My = <ERROR TYPE REF: Symbol not found, for `incorrect.directory.My`>
public final typealias Your = <ERROR TYPE REF: Loop in supertype: /Your -> /Your>
@@ -15,7 +15,7 @@ package other
import test.Test.*
abstract class Factory {
abstract fun createTest(): Test
abstract fun createTest(): <!OTHER_ERROR!>Test<!>
abstract fun createObj(): O
@@ -28,7 +28,7 @@ FILE: main.kt
super<R|kotlin/Any|>()
}
public abstract fun createTest(): R|ERROR CLASS: Symbol not found, for `Test`|
public abstract fun createTest(): <ERROR TYPE REF: Symbol not found, for `Test`>
public abstract fun createObj(): R|test/Test.O|
@@ -9,9 +9,9 @@ abstract class My<T : Some> {
abstract fun foo(arg: T)
abstract val y: My.T
abstract val y: <!OTHER_ERROR, OTHER_ERROR!>My.T<!>
abstract val z: test.My.T
abstract val z: <!OTHER_ERROR, OTHER_ERROR!>test.My.T<!>
class Some : <!UNRESOLVED_REFERENCE!>T<!>()
}
@@ -18,11 +18,11 @@ FILE: typeParameterVsNested.kt
public abstract fun foo(arg: R|test/My.T<T>|): R|kotlin/Unit|
public abstract val y: R|test/My.T<ERROR CLASS: Type argument not defined>|
public get(): R|test/My.T<ERROR CLASS: Type argument not defined>|
public abstract val y: <ERROR TYPE REF: Type argument not defined>
public get(): <ERROR TYPE REF: Type argument not defined>
public abstract val z: R|test/My.T<ERROR CLASS: Type argument not defined>|
public get(): R|test/My.T<ERROR CLASS: Type argument not defined>|
public abstract val z: <ERROR TYPE REF: Type argument not defined>
public get(): <ERROR TYPE REF: Type argument not defined>
public final class Some : R|test/My.T<T>| {
public constructor(): R|test/My.Some| {
@@ -32,7 +32,7 @@ FILE: typeParameterVsNested.kt
}
}
public abstract class Your<T : R|test/Some|> : R|ERROR CLASS: Type parameter cannot be a super-type: T| {
public abstract class Your<T : R|test/Some|> : <ERROR TYPE REF: Type parameter cannot be a super-type: T> {
public constructor<T : R|test/Some|>(): R|test/Your<T>| {
super<R|kotlin/Any|>()
}
@@ -10,4 +10,4 @@ class A<T1, T2> {
fun <R1, R2, R3> foo(c: A<R1, R1>.B<R2, R2>.C<R3, R3>) {}
fun <R3> foo(c: A.B.C<R3, R3>) {}
fun <R3> foo(c: <!OTHER_ERROR!>A.B.C<R3, R3><!>) {}
@@ -27,5 +27,5 @@ FILE: capturedParametersOfInnerClasses.kt
}
public final fun <R1, R2, R3> foo(c: R|A.B.C<R3, R3, R2, R2, R1, R1>|): R|kotlin/Unit| {
}
public final fun <R3> foo(c: R|A.B.C<R3, R3, ERROR CLASS: Type argument not defined, ERROR CLASS: Type argument not defined, ERROR CLASS: Type argument not defined, ERROR CLASS: Type argument not defined>|): R|kotlin/Unit| {
public final fun <R3> foo(c: <ERROR TYPE REF: Type argument not defined>): R|kotlin/Unit| {
}
@@ -58,6 +58,6 @@ class Test6 : E, <!EXPOSED_SUPER_CLASS!>C.CPublic<!> {
}
class Test7 : D.PublicButProtected {
class Test7 : <!OTHER_ERROR!>D.PublicButProtected<!> {
}
@@ -92,7 +92,7 @@ FILE: exposedSupertype.kt
}
}
public final class Test7 : R|ERROR CLASS: Symbol not found, for `D.PublicButProtected`| {
public final class Test7 : <ERROR TYPE REF: Symbol not found, for `D.PublicButProtected`> {
public constructor(): R|Test7| {
super<R|kotlin/Any|>()
}
@@ -1,6 +1,6 @@
// FILE: K1.kt
class K2: J1() {
class Q : Nested()
class Q : <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>Nested<!>()
fun bar() {
<!UNRESOLVED_REFERENCE!>foo<!>()
<!UNRESOLVED_REFERENCE!>baz<!>()
@@ -4,9 +4,9 @@ FILE: K1.kt
super<R|J1|>()
}
public final class Q : R|ERROR CLASS: Symbol not found, for `Nested`| {
public final class Q : <ERROR TYPE REF: Symbol not found, for `Nested`> {
public constructor(): R|K2.Q| {
super<R|ERROR CLASS: Symbol not found, for `Nested`|>()
super<<ERROR TYPE REF: Symbol not found, for `Nested`>>()
}
}
@@ -966,6 +966,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/superclassNotAccessibleFromInterface.kt");
}
@TestMetadata("typeArgumentsNotAllowed.kt")
public void testTypeArgumentsNotAllowed() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/typeArgumentsNotAllowed.kt");
}
@TestMetadata("typeOfAnnotationMember.kt")
public void testTypeOfAnnotationMember() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/typeOfAnnotationMember.kt");
@@ -966,6 +966,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/superclassNotAccessibleFromInterface.kt");
}
@TestMetadata("typeArgumentsNotAllowed.kt")
public void testTypeArgumentsNotAllowed() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/typeArgumentsNotAllowed.kt");
}
@TestMetadata("typeOfAnnotationMember.kt")
public void testTypeOfAnnotationMember() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/typeOfAnnotationMember.kt");
@@ -23,7 +23,7 @@ object CommonDeclarationCheckers : DeclarationCheckers() {
)
override val constructorCheckers: List<FirConstructorChecker> = listOf(
FirConstructorAllowedChecker
FirConstructorAllowedChecker,
)
override val controlFlowAnalyserCheckers: List<FirControlFlowChecker> = listOf(
@@ -15,6 +15,7 @@ object CommonExpressionCheckers : ExpressionCheckers() {
FirQualifiedSupertypeExtendedByOtherSupertypeChecker,
FirProjectionsOnNonClassTypeArgumentChecker,
FirUpperBoundViolatedChecker,
FirTypeArgumentsNotAllowedExpressionChecker,
)
override val functionCallCheckers: List<FirFunctionCallChecker> = listOf()
}
@@ -0,0 +1,72 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.fir.analysis.checkers.expression
import com.intellij.lang.LighterASTNode
import com.intellij.openapi.util.Ref
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiErrorElement
import com.intellij.util.diff.FlyweightCapableTreeStructure
import org.jetbrains.kotlin.KtNodeTypes.TYPE_ARGUMENT_LIST
import org.jetbrains.kotlin.fir.FirLightSourceElement
import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
import org.jetbrains.kotlin.fir.expressions.FirResolvedQualifier
import org.jetbrains.kotlin.fir.lightNode
import org.jetbrains.kotlin.fir.psi
import org.jetbrains.kotlin.psi.KtTypeArgumentList
object FirTypeArgumentsNotAllowedExpressionChecker : FirQualifiedAccessChecker() {
override fun check(functionCall: FirQualifiedAccessExpression, context: CheckerContext, reporter: DiagnosticReporter) {
// analyze type parameters near
// package names
val explicitReceiver = functionCall.explicitReceiver
if (explicitReceiver is FirResolvedQualifier && explicitReceiver.symbol == null) {
if (explicitReceiver.source?.hasAnyArguments() == true) {
reporter.report(explicitReceiver.source)
return
}
}
}
private fun FirSourceElement.hasAnyArguments(): Boolean {
val localPsi = this.psi
val localLight = this.lightNode
if (localPsi != null && localPsi !is PsiErrorElement) {
return localPsi.hasAnyArguments()
} else if (localLight != null && this is FirLightSourceElement) {
return localLight.hasAnyArguments(this.tree)
}
return false
}
private fun PsiElement.hasAnyArguments(): Boolean {
return this.children.size > 1 && this.children[1] is KtTypeArgumentList
}
private fun LighterASTNode.hasAnyArguments(tree: FlyweightCapableTreeStructure<LighterASTNode>): Boolean {
val children = getChildren(tree)
return children.count { it != null } > 1 && children[1]?.tokenType == TYPE_ARGUMENT_LIST
}
private fun LighterASTNode.getChildren(tree: FlyweightCapableTreeStructure<LighterASTNode>): Array<out LighterASTNode?> {
val childrenRef = Ref<Array<LighterASTNode>>()
val childCount = tree.getChildren(this, childrenRef)
return if (childCount > 0) childrenRef.get() else emptyArray()
}
private fun DiagnosticReporter.report(source: FirSourceElement?) {
source?.let {
report(FirErrors.TYPE_ARGUMENTS_NOT_ALLOWED.on(it))
}
}
}
@@ -12,9 +12,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticFactory0
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.fir.declarations.FirErrorFunction
import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic
import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
import org.jetbrains.kotlin.fir.diagnostics.ConeStubDiagnostic
import org.jetbrains.kotlin.fir.diagnostics.*
import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind.*
import org.jetbrains.kotlin.fir.expressions.FirErrorExpression
import org.jetbrains.kotlin.fir.expressions.FirErrorLoop
@@ -22,6 +20,7 @@ import org.jetbrains.kotlin.fir.references.FirErrorNamedReference
import org.jetbrains.kotlin.fir.resolve.calls.CandidateApplicability
import org.jetbrains.kotlin.fir.resolve.diagnostics.*
import org.jetbrains.kotlin.fir.types.FirErrorTypeRef
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
class ErrorNodeDiagnosticCollectorComponent(collector: AbstractDiagnosticCollector) : AbstractDiagnosticCollectorComponent(collector) {
override fun visitErrorLoop(errorLoop: FirErrorLoop, data: CheckerContext) {
@@ -64,8 +63,10 @@ class ErrorNodeDiagnosticCollectorComponent(collector: AbstractDiagnosticCollect
is ConeOperatorAmbiguityError -> FirErrors.ASSIGN_OPERATOR_AMBIGUITY.on(source, diagnostic.candidates)
is ConeVariableExpectedError -> FirErrors.VARIABLE_EXPECTED.on(source)
is ConeTypeMismatchError -> FirErrors.TYPE_MISMATCH.on(source, diagnostic.expectedType, diagnostic.actualType)
is ConeUnexpectedTypeArgumentsError -> FirErrors.TYPE_ARGUMENTS_NOT_ALLOWED.on(diagnostic.source.safeAs() ?: source)
is ConeSimpleDiagnostic -> diagnostic.getFactory().on(source)
is ConeStubDiagnostic -> null
is ConeIntermediateDiagnostic -> null
else -> throw IllegalArgumentException("Unsupported diagnostic type: ${diagnostic.javaClass}")
}
reporter.report(coneDiagnostic)
@@ -80,6 +80,7 @@ object FirErrors {
val PROJECTION_ON_NON_CLASS_TYPE_ARGUMENT by error0<FirSourceElement, PsiElement>()
val UPPER_BOUND_VIOLATED by error0<FirSourceElement, PsiElement>()
val TYPE_ARGUMENTS_NOT_ALLOWED by error0<FirSourceElement, PsiElement>()
val MANY_COMPANION_OBJECTS by error0<FirSourceElement, PsiElement>()
val LOCAL_OBJECT_NOT_ALLOWED by error0<FirSourceElement, PsiElement>()
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.fir.types
import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
import org.jetbrains.kotlin.fir.symbols.ConeClassifierLookupTag
import org.jetbrains.kotlin.name.ClassId
@@ -82,7 +83,7 @@ typealias ConeKotlinErrorType = ConeClassErrorType
class ConeClassLikeErrorLookupTag(override val classId: ClassId) : ConeClassLikeLookupTag()
class ConeClassErrorType(val reason: String) : ConeClassLikeType() {
class ConeClassErrorType(val diagnostic: ConeDiagnostic) : ConeClassLikeType() {
override val lookupTag: ConeClassLikeLookupTag
get() = ConeClassLikeErrorLookupTag(ClassId.fromString("<error>"))
@@ -14,7 +14,7 @@ fun ConeKotlinType.render(): String {
return when (this) {
is ConeTypeVariableType -> "TypeVariable(${this.lookupTag.name})"
is ConeDefinitelyNotNullType -> "${original.render()}!!"
is ConeClassErrorType -> "ERROR CLASS: $reason"
is ConeClassErrorType -> "ERROR CLASS: ${diagnostic.reason}"
is ConeCapturedType -> "CapturedType(${constructor.projection.render()})"
is ConeClassLikeType -> {
buildString {
@@ -838,7 +838,7 @@ class HtmlFirDump internal constructor(private var linkResolver: FirLinkResolver
private fun FlowContent.generate(type: ConeKotlinType) {
when (type) {
is ConeClassErrorType -> error { +type.reason }
is ConeClassErrorType -> error { +type.diagnostic.reason }
is ConeClassLikeType -> return generate(type)
is ConeTypeParameterType -> resolved {
symbolRef(type.lookupTag.toSymbol()) {
@@ -901,7 +901,7 @@ class HtmlFirDump internal constructor(private var linkResolver: FirLinkResolver
unresolved++
generateList(typeRef.qualifier, separator = ".") {
simpleName(it.name)
generateTypeProjections(it.typeArguments)
generateTypeProjections(it.typeArgumentList.typeArguments)
}
if (typeRef.isMarkedNullable) {
+"?"
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
import org.jetbrains.kotlin.fir.declarations.FirFunction
import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
import org.jetbrains.kotlin.fir.declarations.builder.*
import org.jetbrains.kotlin.fir.diagnostics.ConeIntermediateDiagnostic
import org.jetbrains.kotlin.fir.typeContext
import org.jetbrains.kotlin.fir.scopes.impl.withReplacedConeType
import org.jetbrains.kotlin.fir.serialization.FirElementSerializer
@@ -61,7 +62,7 @@ class FirJvmClassCodegen(
private val approximator = object : AbstractTypeApproximator(session.typeContext) {
override fun createErrorType(message: String): SimpleTypeMarker {
return ConeKotlinErrorType(message)
return ConeKotlinErrorType(ConeIntermediateDiagnostic(message))
}
}
@@ -14,8 +14,7 @@ import org.jetbrains.kotlin.fir.builder.FirBuilderDsl
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind
import org.jetbrains.kotlin.fir.diagnostics.*
import org.jetbrains.kotlin.fir.expressions.*
import org.jetbrains.kotlin.fir.expressions.builder.*
import org.jetbrains.kotlin.fir.java.declarations.buildJavaValueParameter
@@ -75,7 +74,9 @@ internal fun FirTypeRef.toConeKotlinTypeProbablyFlexible(
is FirJavaTypeRef -> {
type.toConeKotlinTypeWithoutEnhancement(session, javaTypeParameterStack)
}
else -> ConeKotlinErrorType("Unexpected type reference in JavaClassUseSiteMemberScope: ${this::class.java}")
else -> ConeKotlinErrorType(
ConeSimpleDiagnostic("Unexpected type reference in JavaClassUseSiteMemberScope: ${this::class.java}")
)
}
internal fun JavaType.toFirJavaTypeRef(session: FirSession, javaTypeParameterStack: JavaTypeParameterStack): FirJavaTypeRef {
@@ -217,7 +218,9 @@ private fun FirTypeParameter.getErasedUpperBound(
// E.g. `class A<T extends A, F extends A>`
// To prevent recursive calls return defaultValue() instead
potentiallyRecursiveTypeParameter: FirTypeParameter? = null,
defaultValue: (() -> ConeKotlinType) = { ConeKotlinErrorType("Can't compute erased upper bound of type parameter `$this`") }
defaultValue: (() -> ConeKotlinType) = {
ConeKotlinErrorType(ConeIntermediateDiagnostic("Can't compute erased upper bound of type parameter `$this`"))
}
): ConeKotlinType {
if (this === potentiallyRecursiveTypeParameter) return defaultValue()
@@ -318,7 +321,7 @@ private fun JavaClassifierType.toConeKotlinTypeForFlexibleBound(
val symbol = javaTypeParameterStack[classifier]
ConeTypeParameterTypeImpl(symbol.toLookupTag(), isNullable = !isLowerBound)
}
else -> ConeKotlinErrorType("Unexpected classifier: $classifier")
else -> ConeKotlinErrorType(ConeSimpleDiagnostic("Unexpected classifier: $classifier"))
}
}
@@ -393,7 +396,7 @@ private fun JavaType?.toConeProjectionWithoutEnhancement(
}
is JavaClassifierType -> toConeKotlinTypeWithoutEnhancement(session, javaTypeParameterStack)
is JavaArrayType -> toConeKotlinTypeWithoutEnhancement(session, javaTypeParameterStack)
else -> ConeClassErrorType("Unexpected type argument: $this")
else -> ConeClassErrorType(ConeSimpleDiagnostic("Unexpected type argument: $this"))
}
}
@@ -498,7 +501,7 @@ private fun JavaType.toFirResolvedTypeRef(
forTypeParameterBounds = false
)
return buildResolvedTypeRef {
type = ConeClassErrorType("Unexpected JavaType: $this")
type = ConeClassErrorType(ConeSimpleDiagnostic("Unexpected JavaType: $this"))
}
}
@@ -248,7 +248,7 @@ internal data class TypeAndDefaultQualifiers(
)
internal fun FirTypeRef.typeArguments(): List<FirTypeProjection> =
(this as? FirUserTypeRef)?.qualifier?.lastOrNull()?.typeArguments.orEmpty()
(this as? FirUserTypeRef)?.qualifier?.lastOrNull()?.typeArgumentList?.typeArguments.orEmpty()
internal fun JavaType.typeArguments(): List<JavaType?> = (this as? JavaClassifierType)?.typeArguments.orEmpty()
@@ -47,6 +47,7 @@ import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.fir.types.builder.*
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
import org.jetbrains.kotlin.fir.types.impl.FirQualifierPartImpl
import org.jetbrains.kotlin.fir.types.impl.FirTypeArgumentListImpl
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
import org.jetbrains.kotlin.lexer.KtTokens.*
import org.jetbrains.kotlin.name.ClassId
@@ -1601,10 +1602,16 @@ class DeclarationsConverter(
if (identifier == null)
return buildErrorTypeRef { diagnostic = ConeSimpleDiagnostic("Incomplete user type", DiagnosticKind.Syntax) }
val qualifierPart = FirQualifierPartImpl(identifier.nameAsSafeName()).apply { typeArguments += firTypeArguments }
val theSource = userType.toFirSourceElement()
val qualifierPart = FirQualifierPartImpl(
identifier.nameAsSafeName(),
FirTypeArgumentListImpl(theSource).apply {
typeArguments += firTypeArguments
}
)
return buildUserTypeRef {
source = userType.toFirSourceElement()
source = theSource
isMarkedNullable = isNullable
qualifier.add(qualifierPart)
simpleFirUserType?.qualifier?.let { this.qualifier.addAll(0, it) }
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.fir.builder
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiErrorElement
import com.intellij.psi.tree.IElementType
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.Modality
@@ -35,6 +36,7 @@ import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.fir.types.builder.*
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
import org.jetbrains.kotlin.fir.types.impl.FirQualifierPartImpl
import org.jetbrains.kotlin.fir.types.impl.FirTypeArgumentListImpl
import org.jetbrains.kotlin.fir.types.impl.FirTypePlaceholderProjection
import org.jetbrains.kotlin.lexer.KtTokens.*
import org.jetbrains.kotlin.name.ClassId
@@ -1225,14 +1227,19 @@ class RawFirBuilder(
this.source = source
isMarkedNullable = isNullable
var ktQualifier: KtUserType? = unwrappedElement
do {
val firQualifier = FirQualifierPartImpl(referenceExpression!!.getReferencedNameAsName())
for (typeArgument in ktQualifier!!.typeArguments) {
firQualifier.typeArguments += typeArgument.convert<FirTypeProjection>()
}
val firQualifier = FirQualifierPartImpl(
referenceExpression!!.getReferencedNameAsName(),
FirTypeArgumentListImpl(source).apply {
for (typeArgument in ktQualifier!!.typeArguments) {
typeArguments += typeArgument.convert<FirTypeProjection>()
}
}
)
qualifier.add(firQualifier)
ktQualifier = ktQualifier.qualifier
ktQualifier = ktQualifier!!.qualifier
referenceExpression = ktQualifier?.referenceExpression
} while (referenceExpression != null)
@@ -192,7 +192,7 @@ abstract class AbstractAnnotationDeserializer(
return buildAnnotationCall {
annotationTypeRef = symbol?.let {
buildResolvedTypeRef {
type = it.constructType(emptyList(), isNullable = false)
type = it.constructType(emptyArray(), isNullable = false)
}
} ?: buildErrorTypeRef { diagnostic = ConeUnresolvedSymbolError(classId) }
argumentList = buildArgumentList {
@@ -9,9 +9,9 @@ import org.jetbrains.kotlin.builtins.functions.FunctionClassDescriptor
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
import org.jetbrains.kotlin.fir.declarations.FirTypeParameterRefsOwner
import org.jetbrains.kotlin.fir.declarations.FirTypeParametersOwner
import org.jetbrains.kotlin.fir.declarations.addDefaultBoundIfNecessary
import org.jetbrains.kotlin.fir.declarations.builder.FirTypeParameterBuilder
import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
import org.jetbrains.kotlin.fir.resolve.toSymbol
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.firUnsafe
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
@@ -104,7 +104,7 @@ class FirTypeDeserializer(
//c.components.flexibleTypeDeserializer.create(proto, id, lowerBound, upperBound)
}
return simpleType(proto, attributes) ?: ConeKotlinErrorType("?!id:0")
return simpleType(proto, attributes) ?: ConeKotlinErrorType(ConeSimpleDiagnostic("?!id:0"))
}
private fun typeParameterSymbol(typeParameterId: Int): ConeTypeParameterLookupTag? =
@@ -203,7 +203,9 @@ class FirTypeDeserializer(
}
else -> null
}
return result ?: ConeClassErrorType("Bad suspend function in metadata with constructor: $functionTypeConstructor")
return result ?: ConeClassErrorType(
ConeSimpleDiagnostic("Bad suspend function in metadata with constructor: $functionTypeConstructor")
)
}
private fun typeSymbol(proto: ProtoBuf.Type): ConeClassifierLookupTag? {
@@ -227,7 +229,8 @@ class FirTypeDeserializer(
}
val variance = ProtoEnumFlags.variance(typeArgumentProto.projection)
val type = typeArgumentProto.type(typeTable) ?: return ConeKotlinErrorType("No type recorded")
val type = typeArgumentProto.type(typeTable)
?: return ConeKotlinErrorType(ConeSimpleDiagnostic("No type recorded"))
// TODO: check that here we don't have any attributes
val coneType = type(type, ConeAttributes.Empty)
@@ -10,12 +10,14 @@ import org.jetbrains.kotlin.builtins.functions.FunctionClassDescriptor
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.fir.*
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.diagnostics.ConeIntermediateDiagnostic
import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
import org.jetbrains.kotlin.fir.diagnostics.ConeStubDiagnostic
import org.jetbrains.kotlin.fir.diagnostics.ConeUnexpectedTypeArgumentsError
import org.jetbrains.kotlin.fir.expressions.*
import org.jetbrains.kotlin.fir.expressions.builder.FirResolvedReifiedParameterReferenceBuilder
import org.jetbrains.kotlin.fir.expressions.builder.buildExpressionWithSmartcast
import org.jetbrains.kotlin.fir.expressions.builder.buildResolvedQualifier
import org.jetbrains.kotlin.fir.typeContext
import org.jetbrains.kotlin.fir.references.FirErrorNamedReference
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
import org.jetbrains.kotlin.fir.references.FirSuperReference
@@ -26,10 +28,8 @@ import org.jetbrains.kotlin.fir.resolve.calls.ImplicitDispatchReceiverValue
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnresolvedNameError
import org.jetbrains.kotlin.fir.resolve.providers.FirProvider
import org.jetbrains.kotlin.fir.resolve.providers.FirSymbolProvider
import org.jetbrains.kotlin.fir.resolve.providers.bindSymbolToLookupTag
import org.jetbrains.kotlin.fir.resolve.providers.getSymbolByTypeRef
import org.jetbrains.kotlin.fir.resolve.substitution.AbstractConeSubstitutor
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.resultType
import org.jetbrains.kotlin.fir.scopes.impl.FirDeclaredMemberScopeProvider
import org.jetbrains.kotlin.fir.scopes.impl.withReplacedConeType
@@ -176,7 +176,14 @@ fun FirClassifierSymbol<*>.constructType(
ConeTypeParameterTypeImpl(this.toLookupTag(), isNullable, attributes)
}
is FirClassSymbol -> {
ConeClassLikeTypeImpl(this.toLookupTag(), typeArguments, isNullable, attributes)
val errorTypeRef = typeArguments.find {
it is ConeClassErrorType
}
if (errorTypeRef is ConeClassErrorType) {
ConeClassErrorType(errorTypeRef.diagnostic)
} else {
ConeClassLikeTypeImpl(this.toLookupTag(), typeArguments, isNullable, attributes)
}
}
is FirTypeAliasSymbol -> {
ConeClassLikeTypeImpl(
@@ -190,11 +197,8 @@ fun FirClassifierSymbol<*>.constructType(
}
}
fun FirClassifierSymbol<*>.constructType(parts: List<FirQualifierPart>, isNullable: Boolean): ConeKotlinType =
constructType(parts.toTypeProjections(), isNullable)
fun List<FirQualifierPart>.toTypeProjections(): Array<ConeTypeProjection> =
asReversed().flatMap { it.typeArguments.map { typeArgument -> typeArgument.toConeTypeProjection() } }.toTypedArray()
asReversed().flatMap { it.typeArgumentList.typeArguments.map { typeArgument -> typeArgument.toConeTypeProjection() } }.toTypedArray()
fun FirFunction<*>.constructFunctionalTypeRef(isSuspend: Boolean = false): FirResolvedTypeRef {
val receiverTypeRef = when (this) {
@@ -203,7 +207,7 @@ fun FirFunction<*>.constructFunctionalTypeRef(isSuspend: Boolean = false): FirRe
else -> null
}
val parameters = valueParameters.map {
it.returnTypeRef.coneTypeSafe<ConeKotlinType>() ?: ConeKotlinErrorType("No type for parameter")
it.returnTypeRef.coneTypeSafe<ConeKotlinType>() ?: ConeKotlinErrorType(ConeSimpleDiagnostic("No type for parameter"))
}
val rawReturnType = (this as FirTypedDeclaration).returnTypeRef.coneType
@@ -327,7 +331,7 @@ fun <T : FirResolvable> BodyResolveComponents.typeFromCallee(access: T): FirReso
val implicitReceiver = implicitReceiverStack[labelName]
buildResolvedTypeRef {
source = null
type = implicitReceiver?.type ?: ConeKotlinErrorType("Unresolved this@$labelName")
type = implicitReceiver?.type ?: ConeKotlinErrorType(ConeSimpleDiagnostic("Unresolved this@$labelName"))
}
}
is FirSuperReference -> {
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.fir.declarations.builder.FirTypeParameterBuilder
import org.jetbrains.kotlin.fir.declarations.builder.buildSimpleFunction
import org.jetbrains.kotlin.fir.declarations.builder.buildValueParameter
import org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl
import org.jetbrains.kotlin.fir.diagnostics.ConeIntermediateDiagnostic
import org.jetbrains.kotlin.fir.typeContext
import org.jetbrains.kotlin.fir.resolve.calls.FirSyntheticFunctionSymbol
import org.jetbrains.kotlin.fir.resolve.substitution.substitutorByMap
@@ -348,7 +349,7 @@ private val PUBLIC_METHOD_NAMES_IN_OBJECT = setOf("equals", "hashCode", "getClas
private fun FirSimpleFunction.getFunctionTypeForAbstractMethod(): ConeLookupTagBasedType {
val parameterTypes = valueParameters.map {
it.returnTypeRef.coneTypeSafe<ConeKotlinType>() ?: ConeKotlinErrorType("No type for parameter $it")
it.returnTypeRef.coneTypeSafe<ConeKotlinType>() ?: ConeKotlinErrorType(ConeIntermediateDiagnostic("No type for parameter $it"))
}
return createFunctionalType(
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.fir.resolve.calls
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.diagnostics.ConeIntermediateDiagnostic
import org.jetbrains.kotlin.fir.expressions.FirExpression
import org.jetbrains.kotlin.fir.expressions.FirThisReceiverExpression
import org.jetbrains.kotlin.fir.expressions.builder.buildExpressionWithSmartcast
@@ -43,7 +44,7 @@ abstract class AbstractExplicitReceiverValue<E : FirExpression> : AbstractExplic
override val type: ConeKotlinType
// NB: safe cast is necessary here
get() = explicitReceiver.typeRef.coneTypeSafe()
?: ConeKotlinErrorType("No type calculated for: ${explicitReceiver.renderWithType()}") // TODO: assert here
?: ConeKotlinErrorType(ConeIntermediateDiagnostic("No type calculated for: ${explicitReceiver.renderWithType()}")) // TODO: assert here
override val receiverExpression: FirExpression
get() = explicitReceiver
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.fir.resolve.calls
import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
import org.jetbrains.kotlin.fir.expressions.FirExpression
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccessExpression
import org.jetbrains.kotlin.fir.expressions.FirResolvedQualifier
@@ -235,7 +236,7 @@ internal object CheckCallableReferenceExpectedType : CheckerStage() {
expectedReturnType = extractInputOutputTypesFromCallableReferenceExpectedType(expectedType, callInfo.session)?.outputType
)
is FirVariable<*> -> createKPropertyType(fir, resultingReceiverType, returnTypeRef)
else -> ConeKotlinErrorType("Unknown callable kind: ${fir::class}")
else -> ConeKotlinErrorType(ConeSimpleDiagnostic("Unknown callable kind: ${fir::class}"))
}.let(candidate.substitutor::substituteOrSelf)
candidate.resultingTypeForCallableReference = resultingType
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.resolve.inference
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.PrivateForInline
import org.jetbrains.kotlin.fir.diagnostics.ConeIntermediateDiagnostic
import org.jetbrains.kotlin.fir.resolve.ScopeSession
import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculator
import org.jetbrains.kotlin.fir.types.ConeClassErrorType
@@ -28,7 +29,7 @@ class InferenceComponents(
) {
val approximator: AbstractTypeApproximator = object : AbstractTypeApproximator(ctx) {
override fun createErrorType(message: String): SimpleTypeMarker {
return ConeClassErrorType(message)
return ConeClassErrorType(ConeIntermediateDiagnostic(message))
}
}
val trivialConstraintTypeInferenceOracle = TrivialConstraintTypeInferenceOracle.create(ctx)
@@ -7,6 +7,9 @@ package org.jetbrains.kotlin.fir.resolve.providers.impl
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.diagnostics.ConeIntermediateDiagnostic
import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
import org.jetbrains.kotlin.fir.diagnostics.ConeUnexpectedTypeArgumentsError
import org.jetbrains.kotlin.fir.render
import org.jetbrains.kotlin.fir.resolve.*
import org.jetbrains.kotlin.fir.resolve.providers.bindSymbolToLookupTag
@@ -91,7 +94,16 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver {
areBareTypesAllowed: Boolean
): ConeKotlinType {
if (symbol == null) {
return ConeKotlinErrorType("Symbol not found, for `${typeRef.render()}`")
return ConeKotlinErrorType(ConeSimpleDiagnostic("Symbol not found, for `${typeRef.render()}`"))
}
if (symbol is FirTypeParameterSymbol) {
for (part in typeRef.qualifier) {
if (part.typeArgumentList.typeArguments.isNotEmpty()) {
return ConeClassErrorType(
ConeUnexpectedTypeArgumentsError("Type arguments not allowed", part.typeArgumentList.source)
)
}
}
}
var typeArguments = typeRef.qualifier.toTypeProjections()
if (symbol is FirRegularClassSymbol) {
@@ -101,11 +113,16 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver {
val substitutor = substitutor ?: ConeSubstitutor.Empty
val n = symbol.fir.typeParameters.size - typeArguments.size
if (n < 0) {
typeArguments = (1..symbol.fir.typeParameters.size).map { ConeClassErrorType("Type arguments number mismatch") }.toTypedArray()
typeArguments = (1..symbol.fir.typeParameters.size).map {
ConeClassErrorType(
ConeSimpleDiagnostic("Type arguments number mismatch")
)
}.toTypedArray()
} else {
val argumentsFromOuterClassesAndParents = symbol.fir.typeParameters.takeLast(n).map {
val type = ConeTypeParameterTypeImpl(ConeTypeParameterLookupTag(it.symbol), isNullable = false)
substitutor.substituteOrNull(type) ?: ConeClassErrorType("Type argument not defined")
substitutor.substituteOrNull(type)
?: ConeClassErrorType(ConeSimpleDiagnostic("Type argument not defined"))
}.toTypedArray<ConeTypeProjection>()
typeArguments += argumentsFromOuterClassesAndParents
}
@@ -152,7 +169,7 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver {
}
is FirFunctionTypeRef -> createFunctionalType(typeRef)
is FirDelegatedTypeRef -> resolveType(typeRef.typeRef, scope, areBareTypesAllowed)
is FirDynamicTypeRef -> ConeKotlinErrorType("Not supported: ${typeRef::class.simpleName}")
is FirDynamicTypeRef -> ConeKotlinErrorType(ConeIntermediateDiagnostic("Not supported: ${typeRef::class.simpleName}"))
else -> error("!")
}
}
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.fir.declarations.FirClass
import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
import org.jetbrains.kotlin.fir.expressions.FirStatement
import org.jetbrains.kotlin.fir.resolve.lookupSuperTypes
import org.jetbrains.kotlin.fir.resolve.providers.getNestedClassifierScope
@@ -84,7 +85,7 @@ abstract class FirAbstractTreeTransformerWithSuperTypes(
fun createSubstitutionForSupertype(superType: ConeLookupTagBasedType, session: FirSession): ConeSubstitutor {
val klass = superType.lookupTag.toSymbol(session)?.fir as? FirRegularClass ?: return ConeSubstitutor.Empty
val arguments = superType.typeArguments.map {
it as? ConeKotlinType ?: ConeClassErrorType("illegal projection usage")
it as? ConeKotlinType ?: ConeClassErrorType(ConeSimpleDiagnostic("illegal projection usage"))
}
val mapping = klass.typeParameters.map { it.symbol }.zip(arguments).toMap()
return ConeSubstitutorByMap(mapping)
@@ -324,7 +324,7 @@ class FirCallCompletionResultsWriterTransformer(
val typeRef = argument.typeRef as FirResolvedTypeRef
buildTypeProjectionWithVariance {
source = argument.source
this.typeRef = typeRef.withReplacedConeType(type)
this.typeRef = if (typeRef.type is ConeClassErrorType) typeRef else typeRef.withReplacedConeType(type)
variance = argument.variance
}
}
@@ -6,15 +6,19 @@
package org.jetbrains.kotlin.fir.resolve.transformers
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.fir.PrivateForInline
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
import org.jetbrains.kotlin.fir.diagnostics.ConeUnexpectedTypeArgumentsError
import org.jetbrains.kotlin.fir.resolve.typeResolver
import org.jetbrains.kotlin.fir.scopes.FirScope
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.fir.types.builder.buildErrorTypeRef
import org.jetbrains.kotlin.fir.types.builder.buildResolvedFunctionTypeRef
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
import org.jetbrains.kotlin.fir.visitors.CompositeTransformResult
import org.jetbrains.kotlin.fir.visitors.compose
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
class FirSpecificTypeResolverTransformer(
override val session: FirSession,
@@ -56,11 +60,20 @@ class FirSpecificTypeResolverTransformer(
}
private fun transformType(typeRef: FirTypeRef, resolvedType: ConeKotlinType): CompositeTransformResult<FirTypeRef> {
return buildResolvedTypeRef {
source = typeRef.source
type = resolvedType.takeIfAcceptable() ?: return typeRef.compose()
annotations += typeRef.annotations
delegatedTypeRef = typeRef
return if (resolvedType !is ConeClassErrorType) {
buildResolvedTypeRef {
source = typeRef.source
type = resolvedType.takeIfAcceptable() ?: return typeRef.compose()
annotations += typeRef.annotations
delegatedTypeRef = typeRef
}
} else {
buildErrorTypeRef {
source = resolvedType.diagnostic.safeAs<ConeUnexpectedTypeArgumentsError>()
?.source.safeAs()
?: typeRef.source
diagnostic = resolvedType.diagnostic
}
}.compose()
}
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.builder.buildValueParameter
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyAccessor
import org.jetbrains.kotlin.fir.declarations.synthetic.FirSyntheticProperty
import org.jetbrains.kotlin.fir.diagnostics.ConeIntermediateDiagnostic
import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind
import org.jetbrains.kotlin.fir.expressions.*
@@ -914,7 +915,9 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
if (valueParameter.returnTypeRef is FirImplicitTypeRef) {
valueParameter.transformReturnTypeRef(
StoreType,
valueParameter.returnTypeRef.resolvedTypeFromPrototype(ConeKotlinErrorType("No type for parameter"))
valueParameter.returnTypeRef.resolvedTypeFromPrototype(
ConeKotlinErrorType(ConeSimpleDiagnostic("No type for parameter"))
)
)
}
return valueParameter.compose()
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.fir.*
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
import org.jetbrains.kotlin.fir.diagnostics.ConeStubDiagnostic
import org.jetbrains.kotlin.fir.diagnostics.ConeIntermediateDiagnostic
import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind
import org.jetbrains.kotlin.fir.expressions.*
import org.jetbrains.kotlin.fir.expressions.builder.buildErrorExpression
@@ -77,7 +78,7 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform
callee.replaceBoundSymbol(it)
}
qualifiedAccessExpression.resultType = buildResolvedTypeRef {
type = implicitReceiver?.type ?: ConeKotlinErrorType("Unresolved this@$labelName")
type = implicitReceiver?.type ?: ConeKotlinErrorType(ConeSimpleDiagnostic("Unresolved this@$labelName"))
}
qualifiedAccessExpression
}
@@ -658,7 +659,8 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform
private fun FirConstKind<*>.expectedConeType(): ConeKotlinType {
fun constructLiteralType(classId: ClassId, isNullable: Boolean = false): ConeKotlinType {
val symbol = symbolProvider.getClassLikeSymbolByFqName(classId) ?: return ConeClassErrorType("Missing stdlib class: $classId")
val symbol = symbolProvider.getClassLikeSymbolByFqName(classId)
?: return ConeClassErrorType(ConeSimpleDiagnostic("Missing stdlib class: $classId"))
return symbol.toLookupTag().constructClassType(emptyArray(), isNullable)
}
return when (this) {
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.fir.types
import org.jetbrains.kotlin.fir.diagnostics.ConeIntermediateDiagnostic
import org.jetbrains.kotlin.fir.resolve.*
import org.jetbrains.kotlin.fir.resolve.calls.NoSubstitutor
import org.jetbrains.kotlin.fir.resolve.providers.FirSymbolProvider
@@ -327,7 +328,7 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
}
override fun createErrorTypeWithCustomConstructor(debugName: String, constructor: TypeConstructorMarker): KotlinTypeMarker {
return ConeKotlinErrorType("$debugName c: $constructor")
return ConeKotlinErrorType(ConeIntermediateDiagnostic("$debugName c: $constructor"))
}
override fun CapturedTypeMarker.captureStatus(): CaptureStatus {
@@ -346,7 +347,7 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
override fun TypeConstructorMarker.toErrorType(): SimpleTypeMarker {
require(this is ErrorTypeConstructor)
return ConeClassErrorType(reason)
return ConeClassErrorType(ConeIntermediateDiagnostic(reason))
}
override fun findCommonIntegerLiteralTypesSuperType(explicitSupertypes: List<SimpleTypeMarker>): SimpleTypeMarker? {
@@ -24,7 +24,7 @@ internal class FirErrorTypeRefImpl(
override val diagnostic: ConeDiagnostic,
) : FirErrorTypeRef() {
override val annotations: MutableList<FirAnnotationCall> = mutableListOf()
override val type: ConeKotlinType = ConeClassErrorType(diagnostic.reason)
override val type: ConeKotlinType = ConeClassErrorType(diagnostic)
override val delegatedTypeRef: FirTypeRef? get() = null
override val isSuspend: Boolean = false
@@ -871,9 +871,9 @@ class FirRenderer(builder: StringBuilder, private val mode: RenderMode = RenderM
print(".")
}
print(qualifier.name)
if (qualifier.typeArguments.isNotEmpty()) {
if (qualifier.typeArgumentList.typeArguments.isNotEmpty()) {
print("<")
qualifier.typeArguments.renderSeparated()
qualifier.typeArgumentList.typeArguments.renderSeparated()
print(">")
}
}
@@ -0,0 +1,10 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.fir.diagnostics
class ConeUnexpectedTypeArgumentsError(override val reason: String, val source: Any? = null) : ConeDiagnostic()
class ConeIntermediateDiagnostic(override val reason: String) : ConeDiagnostic()
@@ -12,7 +12,6 @@ import org.jetbrains.kotlin.fir.declarations.FirVariable
import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic
import org.jetbrains.kotlin.fir.expressions.FirExpression
import org.jetbrains.kotlin.fir.symbols.CallableId
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
@@ -5,9 +5,15 @@
package org.jetbrains.kotlin.fir.types
import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.name.Name
interface FirTypeArgumentList {
val source: FirSourceElement
val typeArguments: List<FirTypeProjection>
}
interface FirQualifierPart {
val name: Name
val typeArguments: List<FirTypeProjection>
val typeArgumentList: FirTypeArgumentList
}
@@ -5,10 +5,14 @@
package org.jetbrains.kotlin.fir.types.impl
import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.fir.types.FirQualifierPart
import org.jetbrains.kotlin.fir.types.FirTypeArgumentList
import org.jetbrains.kotlin.fir.types.FirTypeProjection
import org.jetbrains.kotlin.name.Name
class FirQualifierPartImpl(override val name: Name) : FirQualifierPart {
class FirTypeArgumentListImpl(override val source: FirSourceElement) : FirTypeArgumentList {
override val typeArguments = mutableListOf<FirTypeProjection>()
}
}
class FirQualifierPartImpl(override val name: Name, override val typeArgumentList: FirTypeArgumentList) : FirQualifierPart
@@ -24,14 +24,14 @@ open class FirUserTypeRefImpl(
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
for (part in qualifier) {
part.typeArguments.forEach { it.accept(visitor, data) }
part.typeArgumentList.typeArguments.forEach { it.accept(visitor, data) }
}
annotations.forEach { it.accept(visitor, data) }
}
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirUserTypeRefImpl {
for (part in qualifier) {
(part.typeArguments as MutableList<FirTypeProjection>).transformInplace(transformer, data)
(part.typeArgumentList.typeArguments as MutableList<FirTypeProjection>).transformInplace(transformer, data)
}
transformAnnotations(transformer, data)
return this
@@ -147,7 +147,7 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
}
val errorTypeRefImpl = impl(errorTypeRef) {
default("type", "ConeClassErrorType(diagnostic.reason)")
default("type", "ConeClassErrorType(diagnostic)")
default("delegatedTypeRef") {
value = "null"
withGetter = true
+21 -21
View File
@@ -3,53 +3,53 @@
enum class Color {
RED {
fun <T : RED> simpleName(): RED = null!!
fun <T : <!OTHER_ERROR!>RED<!>> simpleName(): <!OTHER_ERROR!>RED<!> = null!!
}
}
class MyColor(val x: Color.RED, y: Color.RED) : Color.RED {
class MyColor(val x: <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>Color.RED<!>, y: <!OTHER_ERROR!>Color.RED<!>) : <!OTHER_ERROR!>Color.RED<!> {
var z: Color.RED = Color.RED
var z: <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>Color.RED<!> = Color.RED
set(arg: Color.RED) { z = arg }
fun foo(arg: Color.RED): Color.RED = arg
fun foo(arg: <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>Color.RED<!>): <!OTHER_ERROR!>Color.RED<!> = arg
fun bar(): Color.RED {
class Local : Color.RED
fun local(arg: Color.RED): Color.RED = arg
val temp: Color.RED = Color.RED
temp as? Color.RED
if (temp is Color.RED) {
return temp as Color.RED
fun bar(): <!OTHER_ERROR!>Color.RED<!> {
class Local : <!OTHER_ERROR!>Color.RED<!>
fun local(arg: <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>Color.RED<!>): <!OTHER_ERROR!>Color.RED<!> = arg
val temp: <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>Color.RED<!> = Color.RED
temp as? <!OTHER_ERROR!>Color.RED<!>
if (temp is <!OTHER_ERROR!>Color.RED<!>) {
return temp as <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>Color.RED<!>
}
val obj = object : Color.RED {}
if (obj is Color.RED) {
val obj = object : <!OTHER_ERROR!>Color.RED<!> {}
if (obj is <!OTHER_ERROR!>Color.RED<!>) {
return obj
}
return Color.RED
}
}
fun create(): Array<Color.RED>? = null
fun create(): <!OTHER_ERROR!>Array<Color.RED>?<!> = null
interface Your<T : Color.RED>
interface Your<T : <!OTHER_ERROR!>Color.RED<!>>
class His : Your<Color.RED>
class His : <!OTHER_ERROR!>Your<Color.RED><!>
fun <T : Color.RED> otherCreate(): Array<T>? = null
fun <T : <!OTHER_ERROR!>Color.RED<!>> otherCreate(): Array<T>? = null
typealias RedAlias = Color.RED
typealias RedAlias = <!OTHER_ERROR!>Color.RED<!>
typealias ArrayOfEnumEntry = Array<Color.RED>
typealias ArrayOfEnumEntry = <!OTHER_ERROR!>Array<Color.RED><!>
typealias ArrayOfEnumEntryAlias = Array<RedAlias>
fun <T> bar(a: Any): T = a as T
fun <T> foo() {
foo<Color.RED>()
foo<<!OTHER_ERROR, UPPER_BOUND_VIOLATED!>Color.RED<!>>()
foo<RedAlias>()
<!INAPPLICABLE_CANDIDATE!>bar<!><Color.RED>(Color.RED)
}
fun Array<Color.RED>.foo(entries: Array<Color.RED>): Array<Color.RED> = null!!
fun <!OTHER_ERROR!>Array<Color.RED><!>.foo(entries: <!OTHER_ERROR!>Array<Color.RED><!>): <!OTHER_ERROR!>Array<Color.RED><!> = null!!
@@ -9,7 +9,7 @@ package foo
fun f() {
class Local1 {
fun g() : bar.X? = null
fun g() : <!OTHER_ERROR!>bar.X?<!> = null
}
class Local2 {
fun g() : foo.bar.X? = null
+1 -1
View File
@@ -45,7 +45,7 @@ class Foo() {}
class Bar<T : Foo>
class Buzz<T> where T : Bar<Int>, T : nioho
class Buzz<T> where T : Bar<Int>, T : <!OTHER_ERROR!>nioho<!>
class X<T : Foo>
class Y<T> where T : Foo, T : Bar<Foo>
@@ -6,4 +6,4 @@ package foo
// FILE: b.kt
@foo fun bar(p: foo): foo = null!!
@<!OTHER_ERROR!>foo<!> fun bar(p: <!OTHER_ERROR!>foo<!>): <!OTHER_ERROR!>foo<!> = null!!
@@ -6,14 +6,14 @@ package foobar.a
import java.*
val a : java.util.List<Int>? = null
val a2 : util.List<Int>? = null
val a3 : LinkedList<Int>? = null
val a2 : <!OTHER_ERROR, OTHER_ERROR!>util.List<Int>?<!> = null
val a3 : <!OTHER_ERROR, OTHER_ERROR!>LinkedList<Int>?<!> = null
// FILE: b.kt
package foobar
abstract class Foo<T>() {
abstract val x : T<Int>
abstract val x : <!TYPE_ARGUMENTS_NOT_ALLOWED, TYPE_ARGUMENTS_NOT_ALLOWED!>T<Int><!>
}
// FILE: b.kt
@@ -21,7 +21,7 @@ package foobar.a
import java.util.*
val b : List<Int>? = a
val b1 : util.List<Int>? = a
val b1 : <!OTHER_ERROR, OTHER_ERROR!>util.List<Int>?<!> = a
// FILE: b.kt
package foobar
+2 -2
View File
@@ -15,10 +15,10 @@ import java.lang.Comparable as Com
val l : MutableList<in Int> = ArrayList<Int>()
fun test(l : java.util.List<Int>) {
val x : java.List
val x : <!OTHER_ERROR!>java.List<!>
val y : java.util.List<Int>
val b : java.lang.Object
val z : java.utils.List<Int>
val z : <!OTHER_ERROR!>java.utils.List<Int><!>
val f : java.io.File? = null
+2 -2
View File
@@ -3,8 +3,8 @@ package unresolved
class Pair<A, B>(val a: A, val b: B)
fun testGenericArgumentsCount() {
val p1: Pair<Int> = Pair(2, 2)
val p2: Pair = Pair(2, 2)
val p1: <!OTHER_ERROR!>Pair<Int><!> = Pair(2, 2)
val p2: <!OTHER_ERROR!>Pair<!> = Pair(2, 2)
}
fun testUnresolved() {
@@ -2,5 +2,5 @@
import java.util.ArrayList
@ArrayList<Int>(1, 1) fun b() {}
@Xoo(<!UNRESOLVED_REFERENCE!>x<!>) fun c() {}
@<!OTHER_ERROR!>Xoo<!>(<!UNRESOLVED_REFERENCE!>x<!>) fun c() {}
@java.lang.Deprecated(<!UNRESOLVED_REFERENCE!>x<!>) fun a() {}
@@ -1,3 +1,3 @@
// Check that there won't be "Rewrite at slice ANNOTATION key" exception - EA-36935
@someErrorAnnotation object Test {
@<!OTHER_ERROR!>someErrorAnnotation<!> object Test {
}
@@ -3,7 +3,7 @@ package test
// Checks that there is no rewrite error at ANNOTATION slice because of resolving annotations for object in lazy resolve and resolving
// object as property (method tries to resolve annotations too).
@BadAnnotation
@<!OTHER_ERROR!>BadAnnotation<!>
object SomeObject
val some = SomeObject
@@ -34,7 +34,7 @@ annotation class Ann8(val p1: Array<String>,
val p4: Array<Ann1>)
annotation class Ann9(
val error: Unresolved = <!UNRESOLVED_REFERENCE!>Unresolved<!>.<!UNRESOLVED_REFERENCE!>VALUE<!>
val error: <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>Unresolved<!> = <!UNRESOLVED_REFERENCE!>Unresolved<!>.<!UNRESOLVED_REFERENCE!>VALUE<!>
)
@@ -1,10 +1,10 @@
// !WITH_NEW_INFERENCE
fun foo(@varargs f : Int) {}
fun foo(@<!OTHER_ERROR!>varargs<!> f : Int) {}
var bar : Int = 1
set(@varargs v) {}
set(@<!OTHER_ERROR!>varargs<!> v) {}
val x : (Int) -> Int = {@varargs x <!SYNTAX!>: Int -> x<!>}
val x : (Int) -> Int = {@<!OTHER_ERROR!>varargs<!> x <!SYNTAX!>: Int -> x<!>}
class Hello(@varargs args: Any) {
class Hello(@<!OTHER_ERROR!>varargs<!> args: Any) {
}
@@ -1,5 +1,5 @@
@Ann class A
@Ann class B
@Ann(1) class C
@kotlin.Ann(1) class D
@kotlin.annotation.Ann(1) class E
@<!OTHER_ERROR!>Ann<!> class A
@<!OTHER_ERROR!>Ann<!> class B
@<!OTHER_ERROR!>Ann<!>(1) class C
@<!OTHER_ERROR!>kotlin.Ann<!>(1) class D
@<!OTHER_ERROR!>kotlin.annotation.Ann<!>(1) class E
@@ -27,7 +27,7 @@ class Test {
fun <T> List<T>.testClassLiteral3() = b<T, Any>::class
fun <T> List<T>.testUnresolved1() = <!UNRESOLVED_REFERENCE!>unresolved<!><T>::foo
fun <T> List<T>.testUnresolved2() = a<unresolved>::foo
fun <T> List<T>.testUnresolved2() = a<<!OTHER_ERROR, UPPER_BOUND_VIOLATED!>unresolved<!>>::foo
fun <T> List<T>.testUnresolved3() = a<<!SYNTAX!><!>>::foo
fun <T> List<T>.testUnresolved4() = <!UNRESOLVED_REFERENCE!>unresolved<!>?::foo
}
@@ -5,7 +5,7 @@
// MODULE: m1
// FILE: bar.kt
fun <T> bar(ff: Err.() -> Unit) {
fun <T> bar(ff: <!OTHER_ERROR!>Err<!>.() -> Unit) {
}
// MODULE: m2(m1)
@@ -2,10 +2,10 @@
class DTO {
val q: Int = 0
operator fun get(prop: KProperty1<*, Int>): Int = 0
operator fun get(prop: <!OTHER_ERROR!>KProperty1<*, Int><!>): Int = 0
}
fun foo(intDTO: DTO?, p: KProperty1<*, Int>) {
fun foo(intDTO: DTO?, p: <!OTHER_ERROR!>KProperty1<*, Int><!>) {
if (intDTO != null) {
intDTO[DTO::q]
intDTO.q
@@ -1 +1 @@
fun testing(a: Any) = a is UnresolvedType<Int>
fun testing(a: Any) = a is <!OTHER_ERROR!>UnresolvedType<Int><!>
@@ -3,7 +3,7 @@
interface B<T>
interface G<T>: B<T>
fun f(p: B<Foo>): Any {
fun f(p: <!OTHER_ERROR, OTHER_ERROR!>B<Foo><!>): Any {
val v = p as G
return checkSubtype<G<*>>(v)
}
@@ -2,7 +2,7 @@
class G<T>
fun foo(p: P) {
fun foo(p: <!OTHER_ERROR, OTHER_ERROR!>P<!>) {
val v = p as G?
checkSubtype<G<*>>(v!!)
}
@@ -1,6 +1,6 @@
class P
fun foo(p: P): Any {
val v = p as G
val v = p as <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>G<!>
return v
}
@@ -1,7 +1,7 @@
// !LANGUAGE: +BareArrayClassLiteral
val a01 = Array::class
val a02 = Array<Array>::class
val a02 = Array<<!OTHER_ERROR!>Array<!>>::class
val a03 = Array<Any?>::class
val a04 = Array<Array<Any?>?>::class
val a05 = Array<IntArray?>::class
@@ -15,12 +15,12 @@ fun case_3() {
}
val x = object<T, K: Comparable<K>> {
fun test() = 10 as T // OK
fun test() = 10 as <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>T<!> // OK
}
fun case_4() {
val x = object<T> {
fun test() = 10 as T
fun test() = 10 as <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>T<!>
}
val y = x.test() // type y is T
@@ -15,12 +15,12 @@ fun case_3() {
}
val x = object<T, K: Comparable<K>> {
fun test() = 10 as T // OK
fun test() = 10 as <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>T<!> // OK
}
fun case_4() {
val x = object<T> {
fun test() = 10 as T
fun test() = 10 as <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>T<!>
}
val y = x.test() // type y is T
@@ -23,7 +23,7 @@ object DefaultHttpClientWithFun : HttpClient by fClient() {
private fun fClient() = HttpClientImpl()
private fun <T> lazy(init: () -> T): kotlin.Lazy<T> {
private fun <T> lazy(init: () -> T): <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>kotlin.Lazy<T><!> {
init()
null!!
}
@@ -9,7 +9,7 @@ public class C {
open class Base ()
class Foo : Data()
class Foo : <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>Data<!>()
companion object : DerivedAbstract()
}
@@ -9,7 +9,7 @@ public class C {
open class Base ()
class Foo : Data()
class Foo : <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>Data<!>()
companion object : DerivedAbstract()
}
@@ -1,6 +1,6 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
data class A(val i: Int, val j: G)
data class B(val i: G, val j: G)
data class A(val i: Int, val j: <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>G<!>)
data class B(val i: <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>G<!>, val j: <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>G<!>)
fun fa(a: A) {
@@ -11,7 +11,7 @@ interface B1<T : B0<*>>
interface AA<T: AA<*>>
interface BB<S : List<AA<*>>>
interface A<T: List<T, T, T>>
interface A<T: <!OTHER_ERROR!>List<T, T, T><!>>
class X<Y>
class D<T : X<in X<out X<T>>>>
@@ -11,7 +11,7 @@ fun test() {
const val <T> a3 = 0
lateinit val <T> a4 = 0
val <T> a5 by Delegate<Int>()
val <T> a6 by <!INAPPLICABLE_CANDIDATE!>Delegate<T>()<!>
val <T> a6 by <!INAPPLICABLE_CANDIDATE!>Delegate<<!OTHER_ERROR, UPPER_BOUND_VIOLATED!>T<!>>()<!>
}
class Delegate<F> {
@@ -11,7 +11,7 @@ fun test() {
const val <T> a3 = 0
lateinit val <T> a4 = 0
val <T> a5 by Delegate<Int>()
val <T> a6 by <!INAPPLICABLE_CANDIDATE!>Delegate<T>()<!>
val <T> a6 by <!INAPPLICABLE_CANDIDATE!>Delegate<<!OTHER_ERROR, UPPER_BOUND_VIOLATED!>T<!>>()<!>
}
class Delegate<F> {
@@ -1,4 +1,4 @@
interface T {
val x: ErrorType
fun getX(): ErrorType1
val x: <!OTHER_ERROR, OTHER_ERROR!>ErrorType<!>
fun getX(): <!OTHER_ERROR!>ErrorType1<!>
}
@@ -3,4 +3,4 @@ enum class MyEnum {
SECOND
}
fun foo(me: MyEnum): Boolean = if (me is MyEnum.FIRST) true else false
fun foo(me: MyEnum): Boolean = if (me is <!OTHER_ERROR!>MyEnum.FIRST<!>) true else false
@@ -2,4 +2,4 @@ enum class E {
ENTRY
}
class A : E.ENTRY
class A : <!OTHER_ERROR!>E.ENTRY<!>
@@ -3,4 +3,4 @@ enum class MyEnum {
SECOND
}
fun foo(me: MyEnum): Boolean = me is MyEnum.FIRST
fun foo(me: MyEnum): Boolean = me is <!OTHER_ERROR!>MyEnum.FIRST<!>
@@ -12,10 +12,10 @@ inline class ULong(private val l: Long)
// FILE: test.kt
annotation class AnnoUB(val ub0: UByte, val ub1: UByte)
annotation class AnnoUS(val us0: UShort, val us1: UShort)
annotation class AnnoUI(val ui0: UInt, val ui1: UInt, val ui2: UInt, val ui3: UInt)
annotation class AnnoUL(val ul0: ULong, val ul1: ULong)
annotation class AnnoUB(val ub0: <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>UByte<!>, val ub1: <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>UByte<!>)
annotation class AnnoUS(val us0: <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>UShort<!>, val us1: <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>UShort<!>)
annotation class AnnoUI(val ui0: <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>UInt<!>, val ui1: <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>UInt<!>, val ui2: <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>UInt<!>, val ui3: <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>UInt<!>)
annotation class AnnoUL(val ul0: <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>ULong<!>, val ul1: <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>ULong<!>)
const val ub0 = <!UNRESOLVED_REFERENCE!>UByte<!>(1)
const val us0 = <!UNRESOLVED_REFERENCE!>UShort<!>(2)
@@ -37,8 +37,8 @@ fun f2() {}
@AnnoUL(ul0, <!UNRESOLVED_REFERENCE!>ULong<!>(5))
fun f3() {}
const val explicit: UInt = <!UNRESOLVED_REFERENCE!>UInt<!>(2)
const val explicit: <!OTHER_ERROR, OTHER_ERROR!>UInt<!> = <!UNRESOLVED_REFERENCE!>UInt<!>(2)
const val nullable: UInt? = <!UNRESOLVED_REFERENCE!>UInt<!>(3)
const val nullable: <!OTHER_ERROR, OTHER_ERROR!>UInt?<!> = <!UNRESOLVED_REFERENCE!>UInt<!>(3)
annotation class NullableAnno(val u: UInt?)
annotation class NullableAnno(val u: <!OTHER_ERROR, OTHER_ERROR, OTHER_ERROR, OTHER_ERROR!>UInt?<!>)

Some files were not shown because too many files have changed in this diff Show More