better test for 'system.compiles'

This commit is contained in:
Araq
2012-07-20 16:53:01 +02:00
parent 8413772063
commit 34efc2cdf9

View File

@@ -1,12 +1,31 @@
discard """
output: '''no'''
output: '''obj has '==': false
int has '==': true
false
true
true
no'''
"""
# test the new 'compiles' feature:
template supports(opr, x: expr): bool {.immediate.} =
compiles(opr(x)) or compiles(opr(x, x))
type
TObj = object
var
myObj {.compileTime.}: TObj
echo "obj has '==': ", supports(`==`, myObj)
echo "int has '==': ", supports(`==`, 45)
echo supports(`++`, 34)
echo supports(`not`, true)
echo supports(`+`, 34)
when compiles(4+5.0 * "hallo"):
echo "yes"
else:
echo "no"