close #8829(add testcase for #8829) (#15866)

This commit is contained in:
flywind 2020-11-06 23:39:20 +08:00 • committed by GitHub
commit fb60e35a54
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

18
tests/overload/t8829.nim Normal file
View file

@ -0,0 +1,18 @@
block:
let txt = "Hello World"
template `[]`[T](p: ptr T, span: Slice[int]): untyped =
toOpenArray(cast[ptr array[0, T]](p)[], span.a, span.b)
doAssert $cast[ptr uint8](txt[0].unsafeAddr)[0 ..< txt.len] ==
"[72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]"
block:
let txt = "Hello World"
template `[]`[T](p: ptr T, span: Slice[int]): untyped =
toOpenArray(cast[ptr array[0, T]](p)[], span.a, span.b)
doAssert $cast[ptr uint8](txt[0].unsafeAddr)[0 ..< txt.len] ==
"[72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]"