[stdlib] Specify AT_MOST_ONCE contract for default-value-like functional parameters KT-54879
This commit is contained in:
committed by
Space Team
parent
dee9fdc02d
commit
fc13ae7b4d
@@ -342,6 +342,9 @@ object Elements : TemplateGroupBase() {
|
||||
returns("T")
|
||||
body {
|
||||
"""
|
||||
contract {
|
||||
callsInPlace(defaultValue, InvocationKind.AT_MOST_ONCE)
|
||||
}
|
||||
if (this is List)
|
||||
return this.getOrElse(index, defaultValue)
|
||||
if (index < 0)
|
||||
@@ -358,6 +361,9 @@ object Elements : TemplateGroupBase() {
|
||||
}
|
||||
body(Sequences) {
|
||||
"""
|
||||
contract {
|
||||
callsInPlace(defaultValue, InvocationKind.AT_MOST_ONCE)
|
||||
}
|
||||
if (index < 0)
|
||||
return defaultValue(index)
|
||||
val iterator = iterator()
|
||||
@@ -374,6 +380,9 @@ object Elements : TemplateGroupBase() {
|
||||
inlineOnly()
|
||||
body {
|
||||
"""
|
||||
contract {
|
||||
callsInPlace(defaultValue, InvocationKind.AT_MOST_ONCE)
|
||||
}
|
||||
return if (index >= 0 && index <= lastIndex) get(index) else defaultValue(index)
|
||||
"""
|
||||
}
|
||||
@@ -388,6 +397,9 @@ object Elements : TemplateGroupBase() {
|
||||
inlineOnly()
|
||||
body {
|
||||
"""
|
||||
contract {
|
||||
callsInPlace(defaultValue, InvocationKind.AT_MOST_ONCE)
|
||||
}
|
||||
return if (index >= 0 && index <= lastIndex) get(index) else defaultValue(index)
|
||||
"""
|
||||
}
|
||||
|
||||
@@ -105,6 +105,7 @@ fun List<MemberBuilder>.writeTo(file: File, targetedSource: TargetedSourceFile)
|
||||
}
|
||||
}
|
||||
if (target.platform == Platform.Common) {
|
||||
writer.appendLine("import kotlin.contracts.*")
|
||||
writer.appendLine("import kotlin.random.*")
|
||||
}
|
||||
if (sourceFile.packageName == "kotlin.collections") {
|
||||
|
||||
Reference in New Issue
Block a user