Conventions for ++/-- support Unit-returning inc/dec functions

This commit is contained in:
Andrey Breslav
2011-04-07 19:50:51 +04:00
parent 39a6b63f0a
commit 566f7cd6b5
5 changed files with 98 additions and 10 deletions
+46
View File
@@ -0,0 +1,46 @@
class IncDec {
fun inc() : IncDec = this
fun dec() : IncDec = this
}
fun testIncDec() {
var x = new IncDec()
x++
++x
x--
--x
x = x++
x = x--
x = ++x
x = --x
}
class WrongIncDec {
fun inc() : Int = 1
fun dec() : Int = 1
}
fun testWrongIncDec() {
var x = new WrongIncDec()
x<error>++</error>
<error>++</error>x
x<error>--</error>
<error>--</error>x
}
class UnitIncDec {
fun inc() : Unit {}
fun dec() : Unit {}
}
fun testUnitIncDec() {
var x = new UnitIncDec()
x++
++x
x--
--x
x = <error>x++</error>
x = <error>x--</error>
x = <error>++x</error>
x = <error>--x</error>
}
@@ -85,3 +85,15 @@ fun <T> tt(t : T) : T {
1 `std::Int.compareTo(Double)`>= 2.0
1 `std::Int.compareTo(Double)`<= 2.0
}
class UnitIncDec {
~uinc~fun inc() : Unit
~udec~fun dec() : Unit
}
fun testUnitIncDec() {
var x = new UnitIncDec()
x`uinc`++
x`udec`--
}