Skip to content

Commit c355424

Browse files
committed
Add ToString singleton op on Ints
1 parent 9711dcc commit c355424

File tree

5 files changed

+9
-1
lines changed

5 files changed

+9
-1
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ class Definitions {
905905
tpnme.Equals, tpnme.NotEquals,
906906
tpnme.Plus, tpnme.Minus, tpnme.Times, tpnme.Div, tpnme.Mod,
907907
tpnme.Lt, tpnme.Gt, tpnme.Ge, tpnme.Le,
908-
tpnme.Abs, tpnme.Negate, tpnme.Min, tpnme.Max,
908+
tpnme.Abs, tpnme.Negate, tpnme.Min, tpnme.Max, tpnme.ToString,
909909
tpnme.Not, tpnme.Xor, tpnme.And, tpnme.Or
910910
).contains(sym.name)
911911

compiler/src/dotty/tools/dotc/core/StdNames.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ object StdNames {
226226
final val Plus: N = "+"
227227
final val S: N = "S"
228228
final val Times: N = "*"
229+
final val ToString: N = "ToString"
229230
final val Xor: N = "^"
230231

231232
final val ClassfileAnnotation: N = "ClassfileAnnotation"

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3636,6 +3636,7 @@ object Types {
36363636
case tpnme.Abs => constantFold1(intValue, _.abs)
36373637
case tpnme.Negate => constantFold1(intValue, x => -x)
36383638
case tpnme.Not => constantFold1(boolValue, x => !x)
3639+
case tpnme.ToString => constantFold1(intValue, _.toString)
36393640
case _ => None
36403641
} else if (args.length == 2) tycon.symbol.name match {
36413642
case tpnme.Equals => constantFold2(constValue, _ == _)

library/src/scala/compiletime/ops/package.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package object ops {
2121
type Negate[X <: Int] <: Int
2222
type Min[X <: Int, Y <: Int] <: Int
2323
type Max[X <: Int, Y <: Int] <: Int
24+
type ToString[X <: Int] <: String
2425

2526
type ![X <: Boolean] <: Boolean
2627
@infix type ^[X <: Boolean, Y <: Boolean] <: Boolean

tests/neg/singleton-ops.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,9 @@ object Test {
9292
val t65: ![false] = true
9393
val t66: ![true] = true // error
9494
val t67: ![false] = false // error
95+
96+
val t68: ToString[213] = "213"
97+
val t69: ToString[-1] = "-1"
98+
val t70: ToString[0] = "-0" // error
99+
val t71: ToString[200] = "100" // error
95100
}

0 commit comments

Comments
 (0)