fix tcompiles
This commit is contained in:
parent
dc33638cb2
commit
9cc23118be
3 changed files with 17 additions and 22 deletions
|
|
@ -1,31 +1,26 @@
|
|||
discard """
|
||||
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))
|
||||
|
||||
template ok(x: expr): stmt =
|
||||
static: assert(x)
|
||||
|
||||
template no(x: expr): stmt =
|
||||
static: assert(not x)
|
||||
|
||||
type
|
||||
TObj = object
|
||||
|
||||
var
|
||||
myObj {.compileTime.}: TObj
|
||||
|
||||
echo "obj has '==': ", supports(`==`, myObj)
|
||||
echo "int has '==': ", supports(`==`, 45)
|
||||
ok supports(`==`, myObj)
|
||||
ok supports(`==`, 45)
|
||||
|
||||
echo supports(`++`, 34)
|
||||
echo supports(`not`, true)
|
||||
echo supports(`+`, 34)
|
||||
no supports(`++`, 34)
|
||||
ok supports(`not`, true)
|
||||
ok supports(`+`, 34)
|
||||
|
||||
no compiles(4+5.0 * "hallo")
|
||||
|
||||
when compiles(4+5.0 * "hallo"):
|
||||
echo "yes"
|
||||
else:
|
||||
echo "no"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue