diff options
author | Oscar NihlgÄrd <oscarnihlgard@gmail.com> | 2019-08-20 17:39:49 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-08-20 17:39:49 +0200 |
commit | 4264e9576d0f3753dcff206fcff06217f2e70833 (patch) | |
tree | bb9d67fce9cf45766d722d41ff974179dac49035 /tests/objvariant | |
parent | d00c8febeec15c4d1503d506474b24e7653eecc5 (diff) | |
download | Nim-4264e9576d0f3753dcff206fcff06217f2e70833.tar.gz |
Consider range type of runtime discrim [feature] (#11432)
Diffstat (limited to 'tests/objvariant')
-rw-r--r-- | tests/objvariant/trt_discrim.nim | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/objvariant/trt_discrim.nim b/tests/objvariant/trt_discrim.nim index 303c0fa55..30ba3d087 100644 --- a/tests/objvariant/trt_discrim.nim +++ b/tests/objvariant/trt_discrim.nim @@ -148,3 +148,50 @@ reject: case kind: of k1: result = KindObj(kind: kind, i32: 1) else: discard + +type + Kind3 = enum + A, B, C, E + + OkRange = range[B..C] + NotOkRange = range[B..E] + + CaseObject = object + case kind: Kind3 + of B, C: + field: int + else: discard + +accept: + let rtDiscriminator: OkRange = B + discard CaseObject(kind: rtDiscriminator, field: 1) + +accept: + let rtDiscriminator = B + discard CaseObject(kind: OkRange(rtDiscriminator), field: 1) + +accept: + const rtDiscriminator: NotOkRange = B + discard CaseObject(kind: rtDiscriminator, field: 1) + +accept: + discard CaseObject(kind: NotOkRange(B), field: 1) + +reject: + let rtDiscriminator: NotOkRange = B + discard CaseObject(kind: rtDiscriminator, field: 1) + +reject: + let rtDiscriminator = B + discard CaseObject(kind: NotOkRange(rtDiscriminator), field: 1) + +reject: + type Obj = object + case x: int + of 0 .. 1000: + field: int + else: + discard + + let x: range[0..15] = 1 + let o = Obj(x: x, field: 1) \ No newline at end of file |