Change logic of constructor delegation call resolution

- If class has type arguments (A<T1,..>) then
  resolve it's delegation call to `this` as for expression A<T1, ..>()
  like type arguments are explicitly specified.

- Same logic works for `super` delegation calls.

- It could be just enough to substitute all candidates before resolve
  but diagnostic messages looks more correct when substitution is
  performed within CandidateResolver.performResolutionForCandidateCall
  because it works the same way as when resolving A<T1, ..>().

 #KT-6992 Fixed
 #KT-6993 Fixed
 #KT-6994 Fixed
This commit is contained in:
Denis Zharkov
2015-03-15 21:40:01 +03:00
parent e37cf6b6a1
commit 36665fe3b8
31 changed files with 392 additions and 20 deletions
@@ -0,0 +1,5 @@
class A<T1, T2> {
constructor(x: T1, y: T2) {}
constructor(x: T1, y: Int) {}
<caret>constructor(x: T1): this(x, 1) {}
}
@@ -0,0 +1,20 @@
class A<T1, T2> {
constructor(x: T1, y: T2) {}
constructor(x: T1, y: Int) {}
<caret>constructor(x: T1): this(x, 1) {}
}
Resolved call:
Candidate descriptor: constructor A<T1, T2>(x: T1, y: Int) defined in A
Resulting descriptor: constructor A<T1, T2>(x: T1, y: Int) defined in A
Explicit receiver kind = NO_EXPLICIT_RECEIVER
Dispatch receiver = NO_RECEIVER
Extension receiver = NO_RECEIVER
Value arguments mapping:
SUCCESS x : T1 = x
SUCCESS y : Int = 1
@@ -0,0 +1,6 @@
open class B<R1, R2>(x: R1, y: R2)
class A<T1, T2> : B<T1, Int> {
<caret>constructor(x: T1, y: Int): super(x, y) {}
}
@@ -0,0 +1,20 @@
open class B<R1, R2>(x: R1, y: R2)
class A<T1, T2> : B<T1, Int> {
<caret>constructor(x: T1, y: Int): super(x, y) {}
}
Resolved call:
Candidate descriptor: constructor B<R1, R2>(x: R1, y: R2) defined in B
Resulting descriptor: constructor B<R1, R2>(x: T1, y: Int) defined in B
Explicit receiver kind = NO_EXPLICIT_RECEIVER
Dispatch receiver = NO_RECEIVER
Extension receiver = NO_RECEIVER
Value arguments mapping:
SUCCESS x : T1 = x
SUCCESS y : Int = y
@@ -0,0 +1,9 @@
open class B<X, Y : X> {
constructor(x: X, y: Y) {}
constructor(x: X, s: String) {}
constructor(y: Y, i: Int) : this(y, "") {}
}
class A<T1, T2 : T1> : B<T1, T2> {
<caret>constructor(x: T1, y: T2): super(x, y) {}
}
@@ -0,0 +1,24 @@
open class B<X, Y : X> {
constructor(x: X, y: Y) {}
constructor(x: X, s: String) {}
constructor(y: Y, i: Int) : this(y, "") {}
}
class A<T1, T2 : T1> : B<T1, T2> {
<caret>constructor(x: T1, y: T2): super(x, y) {}
}
Resolved call:
Candidate descriptor: constructor B<X, Y : X>(x: X, y: Y) defined in B
Resulting descriptor: constructor B<X, Y : X>(x: T1, y: T2) defined in B
Explicit receiver kind = NO_EXPLICIT_RECEIVER
Dispatch receiver = NO_RECEIVER
Extension receiver = NO_RECEIVER
Value arguments mapping:
SUCCESS x : T1 = x
SUCCESS y : T2 = y
@@ -0,0 +1,9 @@
open class B<X, Y : X> {
constructor(x: X, y: Y) {}
constructor(x: X, s: String) {}
constructor(y: Y, i: Int) : this(y, "") {}
}
class A<T1, T2 : T1> : B<T1, T2> {
<caret>constructor(x: T2): super(x, "") {}
}
@@ -0,0 +1,24 @@
open class B<X, Y : X> {
constructor(x: X, y: Y) {}
constructor(x: X, s: String) {}
constructor(y: Y, i: Int) : this(y, "") {}
}
class A<T1, T2 : T1> : B<T1, T2> {
<caret>constructor(x: T2): super(x, "") {}
}
Resolved call:
Candidate descriptor: constructor B<X, Y : X>(x: X, s: String) defined in B
Resulting descriptor: constructor B<X, Y : X>(x: T1, s: String) defined in B
Explicit receiver kind = NO_EXPLICIT_RECEIVER
Dispatch receiver = NO_RECEIVER
Extension receiver = NO_RECEIVER
Value arguments mapping:
SUCCESS x : T1 = x
SUCCESS s : String = ""