Of operator in vm fixes [backport] (#9717)

* fixes #9701
*  fixes #9702
* optimize of statement to bool
This commit is contained in:
cooldome 2018-11-15 12:03:42 +00:00 • committed by Andreas Rumpf
commit 8c1083d3b7
6 changed files with 65 additions and 7 deletions

View file

@ -27,3 +27,54 @@ proc test() =
static:
test()
#----------------------------------------------
# Bugs #9701 and #9702
type
MyKind = enum
kA, kB, kC
Base = ref object of RootObj
x: string
A = ref object of Base
a: string
B = ref object of Base
b: string
C = ref object of B
c: string
template check_templ(n: Base, k: MyKind) =
if k == kA: doAssert(n of A) else: doAssert(not (n of A))
if k in {kB, kC}: doAssert(n of B) else: doAssert(not (n of B))
if k == kC: doAssert(n of C) else: doAssert(not (n of C))
doAssert(n of Base)
proc check_proc(n: Base, k: MyKind) =
if k == kA: doAssert(n of A) else: doAssert(not (n of A))
if k in {kB, kC}: doAssert(n of B) else: doAssert(not (n of B))
if k == kC: doAssert(n of C) else: doAssert(not (n of C))
doAssert(n of Base)
static:
let aa = new(A)
check_templ(aa, kA)
check_proc(aa, kA)
let bb = new(B)
check_templ(bb, kB)
check_proc(bb, kB)
let cc = new(C)
check_templ(cc, kC)
check_proc(cc, kC)
let aa = new(A)
check_templ(aa, kA)
check_proc(aa, kA)
let bb = new(B)
check_templ(bb, kB)
check_proc(bb, kB)
let cc = new(C)
check_templ(cc, kC)
check_proc(cc, kC)