From 1b3725e3954ca01e5f37e82845549bdcce7d3901 Mon Sep 17 00:00:00 2001 From: c-blake Date: Fri, 12 Oct 2018 11:40:07 -0400 Subject: Add `toOpenArray[T](ptr UncheckedArray[T])` for clarity. (#9316) * Add `toOpenArray[T](ptr UncheckedArray[T])` for clarity. `ptr array[0,T]` for some unchecked type already works but A) `UncheckedArray` seems to be the intended future way for this kind of access, and B) essentially all use cases will have a `ptr` for that kind of array source and this call signature lets callers drop the trailing `[]` corresponding to that `ptr` deref. This PR relates to issue https://github.com/nim-lang/Nim/issues/9001 . * Add a test for toOpenArray() for UncheckedArray[T]s. --- tests/system/tsystem_misc.nim | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests') diff --git a/tests/system/tsystem_misc.nim b/tests/system/tsystem_misc.nim index c8189b3b1..3bbb5eff1 100644 --- a/tests/system/tsystem_misc.nim +++ b/tests/system/tsystem_misc.nim @@ -15,6 +15,7 @@ discard """ 1 2 3 +2 48 49 50 @@ -98,6 +99,10 @@ doAssertRaises(IndexError): doAssertRaises(IndexError): foo(toOpenArray(arrNeg, -1, -3)) +type seqqType = ptr UncheckedArray[int] +let qData = cast[seqqType](addr seqq[0]) +oaFirstElm(toOpenArray(qData, 1, 3)) + proc foo(a: openArray[byte]) = for x in a: echo x -- cgit 1.4.1-2-gfad0