Refine signature calculation for methods with default parameters

The problem was that he number of mask parameters for defaults when
generating methods declaration was being calculated upon resulting signature
(with additional parameters: extension receivers, enum name/ordinal),
while on call-sites the masks number was calculated by the arguments number
in resolved call, i.e. by the number of real value parameters.

And because of the additional synthetic parameters (like enum.ordinal) these
two numbers could be different.

The solution is just to use value parameters number in both places.
Note, that we only count value parameters from the original sourse
declaration, ignoring synthetic ones generated by backend (e.g.
Continuation for suspend functions)

 #KT-14565 Fixed
This commit is contained in:
Denis Zharkov
2017-02-22 16:11:27 +03:00
parent 9e03b712de
commit ecec87cbc7
12 changed files with 343 additions and 14 deletions
@@ -0,0 +1,80 @@
// WITH_RUNTIME
// WITH_COROUTINES
import kotlin.coroutines.experimental.*
import kotlin.coroutines.experimental.intrinsics.*
class Controller {
suspend fun suspendHere(
a: String = "abc",
i1: Int = 1,
i2: Int = 1,
i3: Int = 1,
i4: Int = 1,
i5: Int = 1,
i6: Int = 1,
i7: Int = 1,
i8: Int = 1,
i9: Int = 1,
i10: Int = 1,
i11: Int = 1,
i12: Int = 1,
i13: Int = 1,
i14: Int = 1,
i15: Int = 1,
i16: Int = 1,
i17: Int = 1,
i18: Int = 1,
i19: Int = 1,
i20: Int = 1,
i21: Int = 1,
i22: Int = 1,
i23: Int = 1,
i24: Int = 1,
i25: Int = 1,
i26: Int = 1,
i27: Int = 1,
i28: Int = 1,
i29: Int = 1,
i30: Int = 1,
i31: Int = 1
): String = suspendCoroutineOrReturn { x ->
x.resume(a + "#" + (i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 + i10 + i11 + i12 + i13 + i14 + i15 + i16 + i17 + i18 + i19 + i20 + i21 + i22 + i23 + i24 + i25 + i26 + i27 + i28 + i29 + i30 + i31))
COROUTINE_SUSPENDED
}
}
fun builder(c: suspend Controller.() -> Unit) {
c.startCoroutine(Controller(), EmptyContinuation)
}
fun box(): String {
var result = "OK"
builder {
var a = suspendHere()
if (a != "abc#31") {
result = "fail 1: $a"
throw RuntimeException(result)
}
a = suspendHere("cde")
if (a != "cde#31") {
result = "fail 2: $a"
throw RuntimeException(result)
}
a = suspendHere(i2 = 6)
if (a != "abc#36") {
result = "fail 3: $a"
throw RuntimeException(result)
}
a = suspendHere("xyz", 9)
if (a != "xyz#39") {
result = "fail 4: $a"
throw RuntimeException(result)
}
}
return result
}
@@ -0,0 +1,55 @@
enum class ClassTemplate(
// var bug: Int = 1,
var code: Int,
var nameTemplate: Int = 1,
val parent: Int = 1,
val previous: Int = 1,
val progressionEquivalent: Int = 1,
var idDiscipline: Int = 1,
var strictRunningOrder: Int = 1,
var pointsMethod: Int = 1,
var noTimeFaults: Int = 1,
var combineHeights: Int = 1,
var column: Int = 1,
var runningOrderSort: Int = 1,
var programme: Int = 1,
var eliminationTime: Int = 1,
var courseTimeCode: Int = 1,
var teamSize: Int = 1,
var sponsor: Int = 1,
var lateEntryCredits: Int = 1,
var lateEntryFee: Int = 1,
var courseLengthNeeded: Int = 1,
var discretionaryCourseTime: Int = 1,
var isRelay: Int = 1,
var isQualifier: Int = 1,
var generateChildren: Int = 1,
var feedFromParent: Int = 1,
var isNfcAllowed: Int = 1,
var isAddOnAllowed: Int = 1,
var isSpecialEntry: Int = 1,
var isUkaProgression: Int = 1,
var canEnterDirectly: Int = 1,
var isPointRanked: Int = 1,
var isPointRankedDesc: Int = 1
) {
UNDEFINED(code = 56, nameTemplate = 3),
BLAH(code = 57, nameTemplate = 4)
}
fun box(): String {
val x = ClassTemplate.UNDEFINED
val y = ClassTemplate.BLAH
if (x.code != 56 || x.nameTemplate != 3 || x.isAddOnAllowed != 1) return "fail 1"
if (y.code != 57 || y.nameTemplate != 4 || y.isAddOnAllowed != 1) return "fail 2"
return "OK"
}