|
| 1 | +discard """ |
| 2 | + description: ''' |
| 3 | + Tests to make sure type relationship correctly takes effects into |
| 4 | + consideration. |
| 5 | + ''' |
| 6 | + target: native |
| 7 | +""" |
| 8 | + |
| 9 | +# procedures with inferred exception effects |
| 10 | +proc test1() = raise newException(CatchableError, "") |
| 11 | +proc test2() = raise newException(ValueError, "") |
| 12 | +proc test3() = raise newException(IOError, "") |
| 13 | + |
| 14 | +# procedures with declared exception effects |
| 15 | +proc test1e() {.raises: [CatchableError].} = discard |
| 16 | +proc test2e() {.raises: [ValueError].} = discard |
| 17 | +proc test3e() {.raises: [IOError].} = discard |
| 18 | + |
| 19 | +# sub-typing |
| 20 | +doAssert typeof(test2) is typeof(test1) |
| 21 | +doAssert typeof(test3) is typeof(test1) |
| 22 | +# ... but not the other way around |
| 23 | +doAssert typeof(test1) isnot typeof(test2) |
| 24 | +doAssert typeof(test3) isnot typeof(test2) |
| 25 | +# sibling exception types are not compatible |
| 26 | +doAssert typeof(test2) isnot typeof(test3) |
| 27 | +doAssert typeof(test3) isnot typeof(test2) |
| 28 | + |
| 29 | +# declared vs. inferred exception effects are the same, type wise |
| 30 | +doAssert typeof(test1e) is typeof(test1) |
| 31 | +doAssert typeof(test1) is typeof(test1e) |
| 32 | +doAssert typeof(test2e) is typeof(test2) |
| 33 | +doAssert typeof(test2) is typeof(test2e) |
| 34 | + |
| 35 | +doAssert typeof(test2) is proc() {.raises: [CatchableError], nimcall.} |
| 36 | +doAssert typeof(test3) is proc() {.raises: [CatchableError], nimcall.} |
| 37 | +doAssert typeof(test2) isnot proc() {.raises: [IOError], nimcall.} |
0 commit comments