FIR: Do not copy type parameters from class to constructors

Use the same instances from class declaration instead

Otherwise, primary constructor value parameter types when used
in the class body are considered as different from types
based on the class type parameters

See the test genericConstructors.kt, before this commit
"id" call was reported in inapplicable
This commit is contained in:
Denis Zharkov
2019-12-05 13:08:51 +03:00
parent 20d02dd0ee
commit b8984d154b
46 changed files with 212 additions and 153 deletions
@@ -2,7 +2,7 @@ FILE fqName:<root> fileName:/callableRefToGenericMember.kt
CLASS CLASS name:A modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.A
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?]
CONSTRUCTOR visibility:public <> () returnType:<root>.A<T of <uninitialized parent>> [primary]
CONSTRUCTOR visibility:public <> () returnType:<root>.A<T of <root>.A> [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:A modality:FINAL visibility:public superTypes:[kotlin.Any]'
@@ -23,7 +23,7 @@ FILE fqName:<root> fileName:/castToTypeParameter.kt
CLASS CLASS name:Host modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Host
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?]
CONSTRUCTOR visibility:public <> () returnType:<root>.Host<T of <uninitialized parent>> [primary]
CONSTRUCTOR visibility:public <> () returnType:<root>.Host<T of <root>.Host> [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Host modality:FINAL visibility:public superTypes:[kotlin.Any]'
@@ -11,14 +11,14 @@ FILE fqName:<root> fileName:/constructorWithOwnTypeParametersCall.kt
CLASS CLASS name:K1 modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.K1
TYPE_PARAMETER name:T1 index:0 variance: superTypes:[kotlin.Number]
CONSTRUCTOR visibility:public <> () returnType:<root>.K1<T1 of <uninitialized parent>> [primary]
CONSTRUCTOR visibility:public <> () returnType:<root>.K1<T1 of <root>.K1> [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:K1 modality:FINAL visibility:public superTypes:[kotlin.Any]'
CLASS CLASS name:K2 modality:FINAL visibility:public [inner] superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.K1.K2
TYPE_PARAMETER name:T2 index:0 variance: superTypes:[kotlin.CharSequence]
CONSTRUCTOR visibility:public <> () returnType:<root>.K1.K2<T2 of <uninitialized parent>> [primary]
CONSTRUCTOR visibility:public <> () returnType:<root>.K1.K2<T2 of <root>.K1.K2> [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:K2 modality:FINAL visibility:public [inner] superTypes:[kotlin.Any]'
@@ -115,7 +115,7 @@ FILE fqName:<root> fileName:/typeParameterWithPrimitiveNumericSupertype.kt
CLASS CLASS name:F modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.F
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Float]
CONSTRUCTOR visibility:public <> () returnType:<root>.F<T of <uninitialized parent>> [primary]
CONSTRUCTOR visibility:public <> () returnType:<root>.F<T of <root>.F> [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:F modality:FINAL visibility:public superTypes:[kotlin.Any]'
@@ -24,15 +24,15 @@ FILE fqName:<root> fileName:/genericConstructorCallWithTypeArguments.kt
CLASS CLASS name:Box modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Box
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?]
CONSTRUCTOR visibility:public <> (value:T of <uninitialized parent>) returnType:<root>.Box<T of <uninitialized parent>> [primary]
VALUE_PARAMETER name:value index:0 type:T of <uninitialized parent>
CONSTRUCTOR visibility:public <> (value:T of <root>.Box) returnType:<root>.Box<T of <root>.Box> [primary]
VALUE_PARAMETER name:value index:0 type:T of <root>.Box
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Box modality:FINAL visibility:public superTypes:[kotlin.Any]'
PROPERTY name:value visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:value type:T of <root>.Box visibility:private [final]
EXPRESSION_BODY
GET_VAR 'value: T of <uninitialized parent> declared in <root>.Box.<init>' type=T of <uninitialized parent> origin=INITIALIZE_PROPERTY_FROM_PARAMETER
GET_VAR 'value: T of <root>.Box declared in <root>.Box.<init>' type=T of <root>.Box origin=INITIALIZE_PROPERTY_FROM_PARAMETER
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-value> visibility:public modality:FINAL <> ($this:<root>.Box) returnType:T of <root>.Box
correspondingProperty: PROPERTY name:value visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.Box
@@ -2,10 +2,10 @@ FILE fqName:<root> fileName:/genericPropertyRef.kt
CLASS CLASS name:Value modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Value
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?]
CONSTRUCTOR visibility:public <> (value:T of <uninitialized parent>, text:kotlin.String?) returnType:<root>.Value<T of <uninitialized parent>> [primary]
VALUE_PARAMETER name:value index:0 type:T of <uninitialized parent>
CONSTRUCTOR visibility:public <> (value:T of <root>.Value, text:kotlin.String?) returnType:<root>.Value<T of <root>.Value> [primary]
VALUE_PARAMETER name:value index:0 type:T of <root>.Value
EXPRESSION_BODY
TYPE_OP type=T of <uninitialized parent> origin=CAST typeOperand=T of <uninitialized parent>
TYPE_OP type=T of <root>.Value origin=CAST typeOperand=T of <root>.Value
CONST Null type=kotlin.Nothing? value=null
VALUE_PARAMETER name:text index:1 type:kotlin.String?
EXPRESSION_BODY
@@ -16,7 +16,7 @@ FILE fqName:<root> fileName:/genericPropertyRef.kt
PROPERTY name:value visibility:public modality:FINAL [var]
FIELD PROPERTY_BACKING_FIELD name:value type:T of <root>.Value visibility:private
EXPRESSION_BODY
GET_VAR 'value: T of <uninitialized parent> declared in <root>.Value.<init>' type=T of <uninitialized parent> origin=INITIALIZE_PROPERTY_FROM_PARAMETER
GET_VAR 'value: T of <root>.Value declared in <root>.Value.<init>' type=T of <root>.Value origin=INITIALIZE_PROPERTY_FROM_PARAMETER
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-value> visibility:public modality:FINAL <> ($this:<root>.Value) returnType:T of <root>.Value
correspondingProperty: PROPERTY name:value visibility:public modality:FINAL [var]
$this: VALUE_PARAMETER name:<this> type:<root>.Value
@@ -44,7 +44,7 @@ FILE fqName:<root> fileName:/implicitCastToTypeParameter.kt
CLASS CLASS name:Bar modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Bar
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?]
CONSTRUCTOR visibility:public <> () returnType:<root>.Bar<T of <uninitialized parent>> [primary]
CONSTRUCTOR visibility:public <> () returnType:<root>.Bar<T of <root>.Bar> [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Bar modality:FINAL visibility:public superTypes:[kotlin.Any]'
@@ -2,15 +2,15 @@ FILE fqName:<root> fileName:/memberTypeArguments.kt
CLASS CLASS name:GenericClass modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.GenericClass
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?]
CONSTRUCTOR visibility:public <> (value:T of <uninitialized parent>) returnType:<root>.GenericClass<T of <uninitialized parent>> [primary]
VALUE_PARAMETER name:value index:0 type:T of <uninitialized parent>
CONSTRUCTOR visibility:public <> (value:T of <root>.GenericClass) returnType:<root>.GenericClass<T of <root>.GenericClass> [primary]
VALUE_PARAMETER name:value index:0 type:T of <root>.GenericClass
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:GenericClass modality:FINAL visibility:public superTypes:[kotlin.Any]'
PROPERTY name:value visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:value type:T of <root>.GenericClass visibility:private [final]
EXPRESSION_BODY
GET_VAR 'value: T of <uninitialized parent> declared in <root>.GenericClass.<init>' type=T of <uninitialized parent> origin=INITIALIZE_PROPERTY_FROM_PARAMETER
GET_VAR 'value: T of <root>.GenericClass declared in <root>.GenericClass.<init>' type=T of <root>.GenericClass origin=INITIALIZE_PROPERTY_FROM_PARAMETER
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-value> visibility:public modality:FINAL <> ($this:<root>.GenericClass) returnType:T of <root>.GenericClass
correspondingProperty: PROPERTY name:value visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.GenericClass
@@ -23,7 +23,7 @@ FILE fqName:<root> fileName:/memberTypeArguments.kt
VALUE_PARAMETER name:newValue index:0 type:T of <root>.GenericClass
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun withNewValue (newValue: T of <root>.GenericClass): <root>.GenericClass<T of <root>.GenericClass> declared in <root>.GenericClass'
CONSTRUCTOR_CALL 'public constructor <init> (value: T of <uninitialized parent>) [primary] declared in <root>.GenericClass' type=<root>.GenericClass<T of <root>.GenericClass> origin=null
CONSTRUCTOR_CALL 'public constructor <init> (value: T of <root>.GenericClass) [primary] declared in <root>.GenericClass' type=<root>.GenericClass<T of <root>.GenericClass> origin=null
<class: T>: T of <root>.GenericClass
value: GET_VAR 'newValue: T of <root>.GenericClass declared in <root>.GenericClass.withNewValue' type=T of <root>.GenericClass origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
@@ -9,15 +9,15 @@ FILE fqName:<root> fileName:/samConversionInGenericConstructorCall_NI.kt
CLASS CLASS name:Outer modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Outer
TYPE_PARAMETER name:T1 index:0 variance: superTypes:[kotlin.Any?]
CONSTRUCTOR visibility:public <> (j11:<root>.J<T1 of <uninitialized parent>, T1 of <uninitialized parent>>) returnType:<root>.Outer<T1 of <uninitialized parent>> [primary]
VALUE_PARAMETER name:j11 index:0 type:<root>.J<T1 of <uninitialized parent>, T1 of <uninitialized parent>>
CONSTRUCTOR visibility:public <> (j11:<root>.J<T1 of <root>.Outer, T1 of <root>.Outer>) returnType:<root>.Outer<T1 of <root>.Outer> [primary]
VALUE_PARAMETER name:j11 index:0 type:<root>.J<T1 of <root>.Outer, T1 of <root>.Outer>
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Outer modality:FINAL visibility:public superTypes:[kotlin.Any]'
PROPERTY name:j11 visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:j11 type:<root>.J<T1 of <root>.Outer, T1 of <root>.Outer> visibility:private [final]
EXPRESSION_BODY
GET_VAR 'j11: <root>.J<T1 of <uninitialized parent>, T1 of <uninitialized parent>> declared in <root>.Outer.<init>' type=<root>.J<T1 of <uninitialized parent>, T1 of <uninitialized parent>> origin=INITIALIZE_PROPERTY_FROM_PARAMETER
GET_VAR 'j11: <root>.J<T1 of <root>.Outer, T1 of <root>.Outer> declared in <root>.Outer.<init>' type=<root>.J<T1 of <root>.Outer, T1 of <root>.Outer> origin=INITIALIZE_PROPERTY_FROM_PARAMETER
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-j11> visibility:public modality:FINAL <> ($this:<root>.Outer) returnType:<root>.J<T1 of <root>.Outer, T1 of <root>.Outer>
correspondingProperty: PROPERTY name:j11 visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.Outer
@@ -28,15 +28,15 @@ FILE fqName:<root> fileName:/samConversionInGenericConstructorCall_NI.kt
CLASS CLASS name:Inner modality:FINAL visibility:public [inner] superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Outer.Inner
TYPE_PARAMETER name:T2 index:0 variance: superTypes:[kotlin.Any?]
CONSTRUCTOR visibility:public <> (j12:<root>.J<T1 of <root>.Outer, T2 of <uninitialized parent>>) returnType:<root>.Outer.Inner<T2 of <uninitialized parent>> [primary]
VALUE_PARAMETER name:j12 index:0 type:<root>.J<T1 of <root>.Outer, T2 of <uninitialized parent>>
CONSTRUCTOR visibility:public <> (j12:<root>.J<T1 of <root>.Outer, T2 of <root>.Outer.Inner>) returnType:<root>.Outer.Inner<T2 of <root>.Outer.Inner> [primary]
VALUE_PARAMETER name:j12 index:0 type:<root>.J<T1 of <root>.Outer, T2 of <root>.Outer.Inner>
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Inner modality:FINAL visibility:public [inner] superTypes:[kotlin.Any]'
PROPERTY name:j12 visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:j12 type:<root>.J<T1 of <root>.Outer, T2 of <root>.Outer.Inner> visibility:private [final]
EXPRESSION_BODY
GET_VAR 'j12: <root>.J<T1 of <root>.Outer, T2 of <uninitialized parent>> declared in <root>.Outer.Inner.<init>' type=<root>.J<T1 of <root>.Outer, T2 of <uninitialized parent>> origin=INITIALIZE_PROPERTY_FROM_PARAMETER
GET_VAR 'j12: <root>.J<T1 of <root>.Outer, T2 of <root>.Outer.Inner> declared in <root>.Outer.Inner.<init>' type=<root>.J<T1 of <root>.Outer, T2 of <root>.Outer.Inner> origin=INITIALIZE_PROPERTY_FROM_PARAMETER
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-j12> visibility:public modality:FINAL <> ($this:<root>.Outer.Inner) returnType:<root>.J<T1 of <root>.Outer, T2 of <root>.Outer.Inner>
correspondingProperty: PROPERTY name:j12 visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.Outer.Inner
@@ -2,15 +2,15 @@ FILE fqName:<root> fileName:/specializedTypeAliasConstructorCall.kt
CLASS CLASS name:Cell modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Cell
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?]
CONSTRUCTOR visibility:public <> (value:T of <uninitialized parent>) returnType:<root>.Cell<T of <uninitialized parent>> [primary]
VALUE_PARAMETER name:value index:0 type:T of <uninitialized parent>
CONSTRUCTOR visibility:public <> (value:T of <root>.Cell) returnType:<root>.Cell<T of <root>.Cell> [primary]
VALUE_PARAMETER name:value index:0 type:T of <root>.Cell
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Cell modality:FINAL visibility:public superTypes:[kotlin.Any]'
PROPERTY name:value visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:value type:T of <root>.Cell visibility:private [final]
EXPRESSION_BODY
GET_VAR 'value: T of <uninitialized parent> declared in <root>.Cell.<init>' type=T of <uninitialized parent> origin=INITIALIZE_PROPERTY_FROM_PARAMETER
GET_VAR 'value: T of <root>.Cell declared in <root>.Cell.<init>' type=T of <root>.Cell origin=INITIALIZE_PROPERTY_FROM_PARAMETER
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-value> visibility:public modality:FINAL <> ($this:<root>.Cell) returnType:T of <root>.Cell
correspondingProperty: PROPERTY name:value visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.Cell
@@ -34,6 +34,6 @@ FILE fqName:<root> fileName:/specializedTypeAliasConstructorCall.kt
FUN name:test visibility:public modality:FINAL <> () returnType:<root>.Cell<kotlin.Int>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test (): <root>.Cell<kotlin.Int> declared in <root>'
CONSTRUCTOR_CALL 'public constructor <init> (value: T of <uninitialized parent>) [primary] declared in <root>.Cell' type=<root>.Cell<kotlin.Int> origin=null
<class: T>: kotlin.Int
CONSTRUCTOR_CALL 'public constructor <init> (value: kotlin.Int) declared in <root>.Cell' type=<root>.Cell<kotlin.Int> origin=null
<class: T>: <none>
value: CONST Int type=kotlin.Int value=42
@@ -2,15 +2,15 @@ FILE fqName:<root> fileName:/thisOfGenericOuterClass.kt
CLASS CLASS name:Outer modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Outer
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?]
CONSTRUCTOR visibility:public <> (x:T of <uninitialized parent>) returnType:<root>.Outer<T of <uninitialized parent>> [primary]
VALUE_PARAMETER name:x index:0 type:T of <uninitialized parent>
CONSTRUCTOR visibility:public <> (x:T of <root>.Outer) returnType:<root>.Outer<T of <root>.Outer> [primary]
VALUE_PARAMETER name:x index:0 type:T of <root>.Outer
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Outer modality:FINAL visibility:public superTypes:[kotlin.Any]'
PROPERTY name:x visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:x type:T of <root>.Outer visibility:private [final]
EXPRESSION_BODY
GET_VAR 'x: T of <uninitialized parent> declared in <root>.Outer.<init>' type=T of <uninitialized parent> origin=INITIALIZE_PROPERTY_FROM_PARAMETER
GET_VAR 'x: T of <root>.Outer declared in <root>.Outer.<init>' type=T of <root>.Outer origin=INITIALIZE_PROPERTY_FROM_PARAMETER
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-x> visibility:public modality:FINAL <> ($this:<root>.Outer) returnType:T of <root>.Outer
correspondingProperty: PROPERTY name:x visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.Outer