typeof(voidStmt) now works (#17807)

* `typeof(voidStmt)` now works
* remove typeOrVoid
* add condsyms, and reference cligen https://github.com/c-blake/cligen/pull/193
* fixup
* changelog [skip ci]
* fixup
This commit is contained in:
Timothee Cour
2021-04-23 05:36:38 -07:00
committed by GitHub
parent 3516f57e17
commit 2abc936d51
8 changed files with 78 additions and 12 deletions

View File

@@ -35,3 +35,64 @@ ReturnT[void]()
echo ReturnT[string]("abc")
nothing()
block: # typeof(stmt)
proc fn1(): auto =
discard
proc fn2(): auto =
1
doAssert type(fn1()) is void
doAssert typeof(fn1()) is void
doAssert typeof(fn1()) isnot int
doAssert type(fn2()) isnot void
doAssert typeof(fn2()) isnot void
when typeof(fn1()) is void: discard
else: doAssert false
doAssert typeof(1+1) is int
doAssert typeof((discard)) is void
type A1 = typeof(fn1())
doAssert A1 is void
type A2 = type(fn1())
doAssert A2 is void
doAssert A2 is A1
when false:
# xxx: MCS/UFCS doesn't work here: Error: expression 'fn1()' has no type (or is ambiguous)
type A3 = fn1().type
proc bar[T](a: T): string = $T
doAssert bar(1) == "int"
doAssert bar(fn1()) == "void"
proc bar2[T](a: T): bool = T is void
doAssert not bar2(1)
doAssert bar2(fn1())
block:
proc bar3[T](a: T): T = a
let a1 = bar3(1)
doAssert compiles(block:
let a1 = bar3(fn2()))
doAssert not compiles(block:
let a2 = bar3(fn1()))
doAssert compiles(block: bar3(fn1()))
doAssert compiles(bar3(fn1()))
doAssert typeof(bar3(fn1())) is void
doAssert not compiles(sizeof(bar3(fn1())))
block:
var a = 1
doAssert typeof((a = 2)) is void
doAssert typeof((a = 2; a = 3)) is void
doAssert typeof(block:
a = 2; a = 3) is void
block:
var a = 1
template bad1 = echo (a; a = 2)
doAssert not compiles(bad1())
block:
template bad2 = echo (nonexistant; discard)
doAssert not compiles(bad2())