diff options
author | ringabout <43030857+ringabout@users.noreply.github.com> | 2024-08-13 23:08:30 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-13 17:08:30 +0200 |
commit | a33e2b76ae4355db61ecf51aec0ced7690c975ef (patch) | |
tree | 76d0072977d90949c7cd7d36fd4de64da4baea26 /tests/objects/tobject_default_value.nim | |
parent | ddc47feccadf23423d969e970b816b9808335769 (diff) | |
download | Nim-a33e2b76ae4355db61ecf51aec0ced7690c975ef.tar.gz |
supports `default` for range types using `firstOrd` with `nimPreviewRangeDefault` (#23950)
ref https://github.com/nim-lang/Nim/issues/23943
Diffstat (limited to 'tests/objects/tobject_default_value.nim')
-rw-r--r-- | tests/objects/tobject_default_value.nim | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/tests/objects/tobject_default_value.nim b/tests/objects/tobject_default_value.nim index 152b355f4..77837bb84 100644 --- a/tests/objects/tobject_default_value.nim +++ b/tests/objects/tobject_default_value.nim @@ -121,7 +121,7 @@ template main {.dirty.} = rVal: R = default(R) # Works fine objVal = default(Obj) - doAssert rVal == 0 # it should be 1 + doAssert rVal == 1 doAssert objVal.r == 1 block: # bug #16744 @@ -134,7 +134,7 @@ template main {.dirty.} = rVal: R = default(R) # Works fine objVal = Obj() - doAssert rVal == 0 # it should be 1 + doAssert rVal == 1 # it should be 1 doAssert objVal.r == 1 block: # bug #3608 @@ -745,5 +745,19 @@ template main {.dirty.} = doAssert b.list[North] == 1 + block: + type + range1 = range[1..10] + range2 = range[-1..10] + + proc foo = + doAssert default(range1) == 1 + doAssert default(range2) == -1 + + let s = default(array[5, range1]) + doAssert s == [range1 1, 1, 1, 1, 1] + + foo() + static: main() main() |