Expand KDoc of inc() and dec() operators #KT-43701
This commit is contained in:
@@ -32,9 +32,18 @@ constructor(code: UShort) : Comparable<Char> {
|
||||
/** Subtracts the other Int value from this value resulting a Char. */
|
||||
public operator fun minus(other: Int): Char = (value - other).toChar()
|
||||
|
||||
/** Increments this value. */
|
||||
/**
|
||||
* Returns this value incremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.inc
|
||||
*/
|
||||
public operator fun inc(): Char = (value + 1).toChar()
|
||||
/** Decrements this value. */
|
||||
|
||||
/**
|
||||
* Returns this value decremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.dec
|
||||
*/
|
||||
public operator fun dec(): Char = (value - 1).toChar()
|
||||
|
||||
/** Creates a range from this value to the specified [other] value. */
|
||||
|
||||
@@ -174,10 +174,20 @@ public class Byte private constructor() : Number(), Comparable<Byte> {
|
||||
@SinceKotlin("1.1")
|
||||
public operator fun rem(other: Double): Double
|
||||
|
||||
/** Increments this value. */
|
||||
/**
|
||||
* Returns this value incremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.inc
|
||||
*/
|
||||
public operator fun inc(): Byte
|
||||
/** Decrements this value. */
|
||||
|
||||
/**
|
||||
* Returns this value decremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.dec
|
||||
*/
|
||||
public operator fun dec(): Byte
|
||||
|
||||
/** Returns this value. */
|
||||
public operator fun unaryPlus(): Int
|
||||
/** Returns the negative of this value. */
|
||||
@@ -416,10 +426,20 @@ public class Short private constructor() : Number(), Comparable<Short> {
|
||||
@SinceKotlin("1.1")
|
||||
public operator fun rem(other: Double): Double
|
||||
|
||||
/** Increments this value. */
|
||||
/**
|
||||
* Returns this value incremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.inc
|
||||
*/
|
||||
public operator fun inc(): Short
|
||||
/** Decrements this value. */
|
||||
|
||||
/**
|
||||
* Returns this value decremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.dec
|
||||
*/
|
||||
public operator fun dec(): Short
|
||||
|
||||
/** Returns this value. */
|
||||
public operator fun unaryPlus(): Int
|
||||
/** Returns the negative of this value. */
|
||||
@@ -655,10 +675,20 @@ public class Int private constructor() : Number(), Comparable<Int> {
|
||||
@SinceKotlin("1.1")
|
||||
public operator fun rem(other: Double): Double
|
||||
|
||||
/** Increments this value. */
|
||||
/**
|
||||
* Returns this value incremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.inc
|
||||
*/
|
||||
public operator fun inc(): Int
|
||||
/** Decrements this value. */
|
||||
|
||||
/**
|
||||
* Returns this value decremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.dec
|
||||
*/
|
||||
public operator fun dec(): Int
|
||||
|
||||
/** Returns this value. */
|
||||
public operator fun unaryPlus(): Int
|
||||
/** Returns the negative of this value. */
|
||||
@@ -946,10 +976,20 @@ public class Float private constructor() : Number(), Comparable<Float> {
|
||||
@SinceKotlin("1.1")
|
||||
public operator fun rem(other: Double): Double
|
||||
|
||||
/** Increments this value. */
|
||||
/**
|
||||
* Returns this value incremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.inc
|
||||
*/
|
||||
public operator fun inc(): Float
|
||||
/** Decrements this value. */
|
||||
|
||||
/**
|
||||
* Returns this value decremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.dec
|
||||
*/
|
||||
public operator fun dec(): Float
|
||||
|
||||
/** Returns this value. */
|
||||
public operator fun unaryPlus(): Float
|
||||
/** Returns the negative of this value. */
|
||||
@@ -1192,10 +1232,20 @@ public class Double private constructor() : Number(), Comparable<Double> {
|
||||
@SinceKotlin("1.1")
|
||||
public operator fun rem(other: Double): Double
|
||||
|
||||
/** Increments this value. */
|
||||
/**
|
||||
* Returns this value incremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.inc
|
||||
*/
|
||||
public operator fun inc(): Double
|
||||
/** Decrements this value. */
|
||||
|
||||
/**
|
||||
* Returns this value decremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.dec
|
||||
*/
|
||||
public operator fun dec(): Double
|
||||
|
||||
/** Returns this value. */
|
||||
public operator fun unaryPlus(): Double
|
||||
/** Returns the negative of this value. */
|
||||
|
||||
@@ -201,10 +201,18 @@ public class Long internal constructor(
|
||||
@SinceKotlin("1.1")
|
||||
public inline operator fun rem(other: Double): Double = toDouble() % other
|
||||
|
||||
/** Increments this value. */
|
||||
/**
|
||||
* Returns this value incremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.inc
|
||||
*/
|
||||
public operator fun inc(): Long = this + 1L
|
||||
|
||||
/** Decrements this value. */
|
||||
/**
|
||||
* Returns this value decremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.dec
|
||||
*/
|
||||
public operator fun dec(): Long = this - 1L
|
||||
|
||||
/** Returns this value. */
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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 samples.misc
|
||||
|
||||
import samples.*
|
||||
|
||||
class Builtins {
|
||||
|
||||
@Sample
|
||||
fun inc() {
|
||||
val a = 3
|
||||
val b = a.inc()
|
||||
assertPrints(a, "3")
|
||||
assertPrints(b, "4")
|
||||
|
||||
var x = 3
|
||||
val y = x++
|
||||
assertPrints(x, "4")
|
||||
assertPrints(y, "3")
|
||||
|
||||
val z = ++x
|
||||
assertPrints(x, "5")
|
||||
assertPrints(z, "5")
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun dec() {
|
||||
val a = 3
|
||||
val b = a.dec()
|
||||
assertPrints(a, "3")
|
||||
assertPrints(b, "2")
|
||||
|
||||
var x = 3
|
||||
val y = x--
|
||||
assertPrints(x, "2")
|
||||
assertPrints(y, "3")
|
||||
|
||||
val z = --x
|
||||
assertPrints(x, "1")
|
||||
assertPrints(z, "1")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,10 +217,19 @@ public value class UByte @PublishedApi internal constructor(@PublishedApi intern
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun mod(other: ULong): ULong = this.toULong().mod(other)
|
||||
|
||||
/** Increments this value. */
|
||||
/**
|
||||
* Returns this value incremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.inc
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun inc(): UByte = UByte(data.inc())
|
||||
/** Decrements this value. */
|
||||
|
||||
/**
|
||||
* Returns this value decremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.dec
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun dec(): UByte = UByte(data.dec())
|
||||
|
||||
|
||||
@@ -217,10 +217,19 @@ public value class UInt @PublishedApi internal constructor(@PublishedApi interna
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun mod(other: ULong): ULong = this.toULong().mod(other)
|
||||
|
||||
/** Increments this value. */
|
||||
/**
|
||||
* Returns this value incremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.inc
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun inc(): UInt = UInt(data.inc())
|
||||
/** Decrements this value. */
|
||||
|
||||
/**
|
||||
* Returns this value decremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.dec
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun dec(): UInt = UInt(data.dec())
|
||||
|
||||
|
||||
@@ -217,10 +217,19 @@ public value class ULong @PublishedApi internal constructor(@PublishedApi intern
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun mod(other: ULong): ULong = rem(other)
|
||||
|
||||
/** Increments this value. */
|
||||
/**
|
||||
* Returns this value incremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.inc
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun inc(): ULong = ULong(data.inc())
|
||||
/** Decrements this value. */
|
||||
|
||||
/**
|
||||
* Returns this value decremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.dec
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun dec(): ULong = ULong(data.dec())
|
||||
|
||||
|
||||
@@ -217,10 +217,19 @@ public value class UShort @PublishedApi internal constructor(@PublishedApi inter
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun mod(other: ULong): ULong = this.toULong().mod(other)
|
||||
|
||||
/** Increments this value. */
|
||||
/**
|
||||
* Returns this value incremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.inc
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun inc(): UShort = UShort(data.inc())
|
||||
/** Decrements this value. */
|
||||
|
||||
/**
|
||||
* Returns this value decremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.dec
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline operator fun dec(): UShort = UShort(data.dec())
|
||||
|
||||
|
||||
@@ -43,11 +43,19 @@ public class Char private constructor(public val value: Char) : Comparable<Char>
|
||||
public inline operator fun minus(other: Int): Char =
|
||||
(this.toInt() - other).toChar()
|
||||
|
||||
/** Increments this value. */
|
||||
/**
|
||||
* Returns this value incremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.inc
|
||||
*/
|
||||
public inline operator fun inc(): Char =
|
||||
(this.toInt() + 1).toChar()
|
||||
|
||||
/** Decrements this value. */
|
||||
/**
|
||||
* Returns this value decremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.dec
|
||||
*/
|
||||
public inline operator fun dec(): Char =
|
||||
(this.toInt() - 1).toChar()
|
||||
|
||||
|
||||
@@ -209,11 +209,19 @@ public class Byte private constructor(public val value: Byte) : Number(), Compar
|
||||
public inline operator fun rem(other: Double): Double =
|
||||
this.toDouble() % other
|
||||
|
||||
/** Increments this value. */
|
||||
/**
|
||||
* Returns this value incremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.inc
|
||||
*/
|
||||
public inline operator fun inc(): Byte =
|
||||
(this + 1).toByte()
|
||||
|
||||
/** Decrements this value. */
|
||||
/**
|
||||
* Returns this value decremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.dec
|
||||
*/
|
||||
public inline operator fun dec(): Byte =
|
||||
(this - 1).toByte()
|
||||
|
||||
@@ -545,11 +553,19 @@ public class Short private constructor(public val value: Short) : Number(), Comp
|
||||
public inline operator fun rem(other: Double): Double =
|
||||
this.toDouble() % other
|
||||
|
||||
/** Increments this value. */
|
||||
/**
|
||||
* Returns this value incremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.inc
|
||||
*/
|
||||
public inline operator fun inc(): Short =
|
||||
(this + 1).toShort()
|
||||
|
||||
/** Decrements this value. */
|
||||
/**
|
||||
* Returns this value decremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.dec
|
||||
*/
|
||||
public inline operator fun dec(): Short =
|
||||
(this - 1).toShort()
|
||||
|
||||
@@ -885,11 +901,19 @@ public class Int private constructor(val value: Int) : Number(), Comparable<Int>
|
||||
public inline operator fun rem(other: Double): Double =
|
||||
this.toDouble() % other
|
||||
|
||||
/** Increments this value. */
|
||||
/**
|
||||
* Returns this value incremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.inc
|
||||
*/
|
||||
public inline operator fun inc(): Int =
|
||||
this + 1
|
||||
|
||||
/** Decrements this value. */
|
||||
/**
|
||||
* Returns this value decremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.dec
|
||||
*/
|
||||
// TODO: Fix test compiler/testData/codegen/box/functions/invoke/invoke.kt with inline dec
|
||||
public operator fun dec(): Int =
|
||||
this - 1
|
||||
@@ -1275,11 +1299,19 @@ public class Long private constructor(val value: Long) : Number(), Comparable<Lo
|
||||
public inline operator fun rem(other: Double): Double =
|
||||
this.toDouble() % other
|
||||
|
||||
/** Increments this value. */
|
||||
/**
|
||||
* Returns this value incremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.inc
|
||||
*/
|
||||
public inline operator fun inc(): Long =
|
||||
this + 1L
|
||||
|
||||
/** Decrements this value. */
|
||||
/**
|
||||
* Returns this value decremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.dec
|
||||
*/
|
||||
public inline operator fun dec(): Long =
|
||||
this - 1L
|
||||
|
||||
@@ -1651,11 +1683,19 @@ public class Float private constructor(public val value: Float) : Number(), Comp
|
||||
public inline operator fun rem(other: Double): Double =
|
||||
this.toDouble() % other
|
||||
|
||||
/** Increments this value. */
|
||||
/**
|
||||
* Returns this value incremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.inc
|
||||
*/
|
||||
public inline operator fun inc(): Float =
|
||||
this + 1.0f
|
||||
|
||||
/** Decrements this value. */
|
||||
/**
|
||||
* Returns this value decremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.dec
|
||||
*/
|
||||
public inline operator fun dec(): Float =
|
||||
this - 1.0f
|
||||
|
||||
@@ -1957,11 +1997,19 @@ public class Double private constructor(public val value: Double) : Number(), Co
|
||||
public operator fun rem(other: Double): Double =
|
||||
this - (wasm_f64_nearest(this / other) * other)
|
||||
|
||||
/** Increments this value. */
|
||||
/**
|
||||
* Returns this value incremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.inc
|
||||
*/
|
||||
public inline operator fun inc(): Double =
|
||||
this + 1.0
|
||||
|
||||
/** Decrements this value. */
|
||||
/**
|
||||
* Returns this value decremented by one.
|
||||
*
|
||||
* @sample samples.misc.Builtins.dec
|
||||
*/
|
||||
public inline operator fun dec(): Double =
|
||||
this - 1.0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user