Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style usages part one (openarray => openArray) #19321

Merged
merged 2 commits into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/arc/tmovebug.nim
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ when false:

# bug #13456

iterator combinations[T](s: openarray[T], k: int): seq[T] =
iterator combinations[T](s: openArray[T], k: int): seq[T] =
let n = len(s)
assert k >= 0 and k <= n
var pos = newSeq[int](k)
Expand Down Expand Up @@ -455,7 +455,7 @@ initFoo7(2)


# bug #14902
iterator zip[T](s: openarray[T]): (T, T) =
iterator zip[T](s: openArray[T]): (T, T) =
var i = 0
while i < 10:
yield (s[i mod 2], s[i mod 2 + 1])
Expand Down
4 changes: 2 additions & 2 deletions tests/arc/tmovebugcopy.nim
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ when false:

# bug #13456

iterator combinations[T](s: openarray[T], k: int): seq[T] =
iterator combinations[T](s: openArray[T], k: int): seq[T] =
let n = len(s)
assert k >= 0 and k <= n
var pos = newSeq[int](k)
Expand Down Expand Up @@ -416,7 +416,7 @@ initFoo7(2)


# bug #14902
iterator zip[T](s: openarray[T]): (T, T) =
iterator zip[T](s: openArray[T]): (T, T) =
var i = 0
while i < 10:
yield (s[i mod 2], s[i mod 2 + 1])
Expand Down
2 changes: 1 addition & 1 deletion tests/array/tarray.nim
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ block tarray:
arr: TMyarray


proc sum(a: openarray[int]): int =
proc sum(a: openArray[int]): int =
result = 0
var i = 0
while i < len(a):
Expand Down
4 changes: 2 additions & 2 deletions tests/async/tioselectors.nim
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ when not defined(windows):
events: set[Event]

proc vnode_test(): bool =
proc validate(test: openarray[ReadyKey],
check: openarray[valType]): bool =
proc validate(test: openArray[ReadyKey],
check: openArray[valType]): bool =
result = false
if len(test) == len(check):
for checkItem in check:
Expand Down
4 changes: 2 additions & 2 deletions tests/closure/tclosure.nim
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ joinable: false


block tclosure:
proc map(n: var openarray[int], fn: proc (x: int): int {.closure}) =
proc map(n: var openArray[int], fn: proc (x: int): int {.closure}) =
for i in 0..n.len-1: n[i] = fn(n[i])

proc each(n: openarray[int], fn: proc(x: int) {.closure.}) =
proc each(n: openArray[int], fn: proc(x: int) {.closure.}) =
for i in 0..n.len-1:
fn(n[i])

Expand Down
2 changes: 1 addition & 1 deletion tests/compiles/trecursive_generic_in_compiles.nim
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ proc `==`*[T](xs, ys: List[T]): bool =

proc asList*[T](xs: varargs[T]): List[T] =
## Creates list from varargs
proc initListImpl(i: int, xs: openarray[T]): List[T] =
proc initListImpl(i: int, xs: openArray[T]): List[T] =
if i > high(xs):
Nil[T]()
else:
Expand Down
8 changes: 4 additions & 4 deletions tests/concepts/tconcepts_issues.nim
Original file line number Diff line number Diff line change
Expand Up @@ -324,15 +324,15 @@ block t6691:
block t6782:
type
Reader = concept c
c.read(openarray[byte], int, int) is int
c.read(openArray[byte], int, int) is int
Rdr = concept c
c.rd(openarray[byte], int, int) is int
c.rd(openArray[byte], int, int) is int

type TestFile = object

proc read(r: TestFile, dest: openarray[byte], offset: int, limit: int): int =
proc read(r: TestFile, dest: openArray[byte], offset: int, limit: int): int =
result = 0
proc rd(r: TestFile, dest: openarray[byte], offset: int, limit: int): int =
proc rd(r: TestFile, dest: openArray[byte], offset: int, limit: int): int =
result = 0

doAssert TestFile is Reader
Expand Down
2 changes: 1 addition & 1 deletion tests/converter/tconverter_with_varargs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type
converter to_py*(i: int) : PPyRef = nil

when false:
proc to_tuple*(vals: openarray[PPyRef]): PPyRef =
proc to_tuple*(vals: openArray[PPyRef]): PPyRef =
discard

proc abc(args: varargs[PPyRef]) =
Expand Down
8 changes: 4 additions & 4 deletions tests/cpp/tcovariancerules.nim
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,16 @@ proc wantsCovariantSeq2(s: seq[AnimalRef]) =
proc wantsCovariantSeq3(s: seq[RefAlias[Animal]]) =
for a in s: echo a.x

proc wantsCovariantOpenArray(s: openarray[ref Animal]) =
proc wantsCovariantOpenArray(s: openArray[ref Animal]) =
for a in s: echo a.x

proc modifiesCovariantOpenArray(s: var openarray[ref Animal]) =
proc modifiesCovariantOpenArray(s: var openArray[ref Animal]) =
for a in s: echo a.x

proc modifiesDerivedOpenArray(s: var openarray[ref Dog]) =
proc modifiesDerivedOpenArray(s: var openArray[ref Dog]) =
for a in s: echo a.x

proc wantsNonCovariantOpenArray(s: openarray[Animal]) =
proc wantsNonCovariantOpenArray(s: openArray[Animal]) =
for a in s: echo a.x

proc wantsCovariantArray(s: array[2, ref Animal]) =
Expand Down
2 changes: 1 addition & 1 deletion tests/destructor/tmove_objconstr.nim
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ proc myfuncLoop(x: int): MySeqNonCopyable =
discard myfuncLoop(3)

#------------------------------------------------------------
# Move into table via openarray
# Move into table via openArray
#------------------------------------------------------------

type
Expand Down
2 changes: 1 addition & 1 deletion tests/errmsgs/t17460.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ discard """
errormsg: "wrong number of variables"
"""

iterator xclusters*[T](a: openarray[T]; s: static[int]): array[s, T] {.inline.} =
iterator xclusters*[T](a: openArray[T]; s: static[int]): array[s, T] {.inline.} =
var result: array[s, T] # iterators have no default result variable
var i = 0
while i < len(a):
Expand Down
2 changes: 1 addition & 1 deletion tests/errmsgs/tproper_stacktrace.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import strscans, strutils
proc raiseTestException*() =
raise newException(Exception, "test")

proc matchStackTrace(actualEntries: openarray[StackTraceEntry], expected: string) =
proc matchStackTrace(actualEntries: openArray[StackTraceEntry], expected: string) =
var expectedEntries = newSeq[StackTraceEntry]()
var i = 0

Expand Down
4 changes: 2 additions & 2 deletions tests/errmsgs/tsigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ block:
echo foo(fun)

block:
# bug #10285 Function signature don't match when inside seq/array/openarray
# bug #10285 Function signature don't match when inside seq/array/openArray
# Note: the error message now shows `closure` which helps debugging the issue
# out why it doesn't match
proc takesFunc(f: proc (x: int) {.gcsafe, locks: 0.}) =
echo "takes single Func"
proc takesFuncs(fs: openarray[proc (x: int) {.gcsafe, locks: 0.}]) =
proc takesFuncs(fs: openArray[proc (x: int) {.gcsafe, locks: 0.}]) =
echo "takes multiple Func"
takesFunc(proc (x: int) {.gcsafe, locks: 0.} = echo x) # works
takesFuncs([proc (x: int) {.gcsafe, locks: 0.} = echo x]) # fails
Expand Down
2 changes: 1 addition & 1 deletion tests/generics/tgenerics_issues.nim
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ block t7854:


block t5864:
proc defaultStatic(s: openarray, N: static[int] = 1): int = N
proc defaultStatic(s: openArray, N: static[int] = 1): int = N
proc defaultGeneric[T](a: T = 2): int = a

let a = [1, 2, 3, 4].defaultStatic()
Expand Down
4 changes: 2 additions & 2 deletions tests/generics/tgenerics_various.nim
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ block tvarargs_vs_generics:
echo "direct"
proc withDirectType[T](arg: T) =
echo "generic"
proc withOpenArray(args: openarray[string]) =
echo "openarray"
proc withOpenArray(args: openArray[string]) =
echo "openArray"
proc withOpenArray[T](arg: T) =
echo "generic"
proc withVarargs(args: varargs[string]) =
Expand Down
2 changes: 1 addition & 1 deletion tests/iter/titer13.nim
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ block:
echo a

block t5859:
proc flatIterator[T](s: openarray[T]): auto {.noSideEffect.}=
proc flatIterator[T](s: openArray[T]): auto {.noSideEffect.}=
result = iterator(): auto =
when (T is not seq|array):
for item in s:
Expand Down
4 changes: 2 additions & 2 deletions tests/iter/titer_issues.nim
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ block t3837_chained:


block t3221_complex:
iterator permutations[T](ys: openarray[T]): seq[T] =
iterator permutations[T](ys: openArray[T]): seq[T] =
var
d = 1
c = newSeq[int](ys.len)
Expand Down Expand Up @@ -228,7 +228,7 @@ block t2023_objiter:

block:
# bug #13739
iterator myIter(arg: openarray[int]): int =
iterator myIter(arg: openArray[int]): int =
var tmp = 0
let len = arg.len
while tmp < len:
Expand Down
2 changes: 1 addition & 1 deletion tests/iter/tmoditer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ proc `=copy`(dst: var NonCopyable, src: NonCopyable) {.error.}
proc `=sink`(dst: var NonCopyable, src: NonCopyable) =
dst.x = src.x

iterator lentItems[T](a: openarray[T]): lent T =
iterator lentItems[T](a: openArray[T]): lent T =
for i in 0..a.high:
yield a[i]

Expand Down
2 changes: 1 addition & 1 deletion tests/iter/tpermutations.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ perm: 6778800.0 det: 0.0

import sequtils, sugar

iterator permutations*[T](ys: openarray[T]): tuple[perm: seq[T], sign: int] =
iterator permutations*[T](ys: openArray[T]): tuple[perm: seq[T], sign: int] =
var
d = 1
c = newSeq[int](ys.len)
Expand Down
4 changes: 2 additions & 2 deletions tests/js/t9410.nim
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,10 @@ template tests =
doAssert seqOfSeqs == @[@[10, 2], @[30, 4]]

when false:
block: # openarray
block: # openArray
# Error: internal error: genAddr: nkStmtListExpr
var calls = 0
proc getvarint(x: var openarray[int]): var int =
proc getvarint(x: var openArray[int]): var int =
calls += 1
if true:
x[1]
Expand Down
2 changes: 1 addition & 1 deletion tests/js/tbasics.nim
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ for x in someGlobal: doAssert(x == 0)
proc tdefault =
var x = default(int)
doAssert(x == 0)
proc inner(v: openarray[string]) =
proc inner(v: openArray[string]) =
doAssert(v.len == 0)

inner(default(seq[string]))
Expand Down
4 changes: 2 additions & 2 deletions tests/js/tbyvar.nim
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ proc main =

main()

# Test: pass var seq to var openarray
# Test: pass var seq to var openArray
var s = @[2, 1]
proc foo(a: var openarray[int]) = a[0] = 123
proc foo(a: var openArray[int]) = a[0] = 123

proc bar(s: var seq[int], a: int) =
doAssert(a == 5)
Expand Down
2 changes: 1 addition & 1 deletion tests/lent/tbasic_lent_check.nim
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ template main2 = # bug #15958
p[] = 20.0
doAssert byLent(p)[] == 20.0

proc byLent2[T](a: openarray[T]): lent T = a[0]
proc byLent2[T](a: openArray[T]): lent T = a[0]
doAssert byLent2(a) == 11
doAssert byLent2(a).unsafeAddr == a[0].unsafeAddr
doAssert byLent2(b) == 21
Expand Down
2 changes: 1 addition & 1 deletion tests/magics/tmagics.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ block tlowhigh:
for i in low(a) .. high(a):
a[i] = 0

proc sum(a: openarray[int]): int =
proc sum(a: openArray[int]): int =
result = 0
for i in low(a)..high(a):
inc(result, a[i])
Expand Down
2 changes: 1 addition & 1 deletion tests/manyloc/named_argument_bug/tri_engine/gfx/gl/gl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ else:
const
glRealType* = cGLfloat

proc setUniformV4*[T](loc: GLint, vecs: var openarray[TV4[T]]) =
proc setUniformV4*[T](loc: GLint, vecs: var openArray[TV4[T]]) =
glUniform4fv(loc, vecs.len.GLsizei, cast[ptr GLfloat](vecs[0].addr))

proc setUniformV4*[T](loc: GLint, vec: TV4[T]) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ proc newVert*(rect: rect.TRect): seq[TVert] =
proc newVertAttrib(i: GLuint, size: GLint, stride: GLsizei, offset: GLvoid): TVertAttrib =
TVertAttrib(i: i, size: size, stride: stride, offset: offset)

proc genBuf*[T](vboTarget, objUsage: GLenum, data: var openarray[T]): GLuint =
proc genBuf*[T](vboTarget, objUsage: GLenum, data: var openArray[T]): GLuint =
result = 0.GLuint
?glGenBuffers(1, result.addr)
?glBindBuffer(vboTarget, result)
Expand Down
2 changes: 1 addition & 1 deletion tests/misc/t9039.nim
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ but expression 'nesting + 1' is of type: int
# line 15
func default(T: typedesc[array]): T = discard
doAssert default(array[3, int]) == [0, 0, 0]
func shapeBad*[T: not char](s: openarray[T], rank: static[int], nesting = 0, parent_shape = default(array[rank, int])): array[rank, int] =
func shapeBad*[T: not char](s: openArray[T], rank: static[int], nesting = 0, parent_shape = default(array[rank, int])): array[rank, int] =
result = parent_shape
result[nesting] = s.len
when (T is seq|array):
Expand Down
2 changes: 1 addition & 1 deletion tests/misc/theaproots.nim
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ proc acc(x: var Foo): var ref Bar =

proc test(maybeFoo: var Foo,
maybeSeq: var seq[ref Bar],
bars: var openarray[ref Bar],
bars: var openArray[ref Bar],
maybeTup: var Tup) =
var bb: ref Bar
maybeFoo.rmaybe = bb
Expand Down
2 changes: 1 addition & 1 deletion tests/misc/tsimplesort.nim
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ proc initTable*[A, B](initialSize=64): TTable[A, B] =
result.counter = 0
newSeq(result.data, initialSize)

proc toTable*[A, B](pairs: openarray[tuple[key: A,
proc toTable*[A, B](pairs: openArray[tuple[key: A,
val: B]]): TTable[A, B] =
## creates a new hash table that contains the given `pairs`.
result = initTable[A, B](nextPowerOfTwo(pairs.len+10))
Expand Down
2 changes: 1 addition & 1 deletion tests/openarray/topena1.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ discard """
# Tests a special bug

var
x: ref openarray[string] #ERROR_MSG invalid type
x: ref openArray[string] #ERROR_MSG invalid type
4 changes: 2 additions & 2 deletions tests/openarray/topenarrayrepr.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ discard """
output: "5 - [1]"
"""
type
TProc = proc (n: int, m: openarray[int64]) {.nimcall.}
TProc = proc (n: int, m: openArray[int64]) {.nimcall.}

proc Foo(x: int, P: TProc) =
P(x, [ 1'i64 ])

proc Bar(n: int, m: openarray[int64]) =
proc Bar(n: int, m: openArray[int64]) =
echo($n & " - " & repr(m))

Foo(5, Bar) #OUT 5 - [1]
2 changes: 1 addition & 1 deletion tests/openarray/topenlen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ discard """

proc choose(b: openArray[string]): string = return b[0]

proc p(a, b: openarray[string]): int =
proc p(a, b: openArray[string]): int =
result = a.len + b.len - 1
for j in 0 .. a.len: inc(result)
discard choose(a)
Expand Down
6 changes: 3 additions & 3 deletions tests/openarray/tptrarrayderef.nim
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ var
raa = [11,12,13]

#bug #3586
proc mutate[T](arr:openarray[T], brr: openArray[T]) =
proc mutate[T](arr:openArray[T], brr: openArray[T]) =
for i in 0..arr.len-1:
doAssert(arr[i] == brr[i])

mutate(arr, arr)

#bug #2240
proc f(a: openarray[int], b: openArray[int]) =
proc f(a: openArray[int], b: openArray[int]) =
for i in 0..a.len-1:
doAssert(a[i] == b[i])

Expand All @@ -37,7 +37,7 @@ ra[2] = 13
f(ra[], raa)

#bug #2240b
proc fillBuffer(buf: var openarray[char]) =
proc fillBuffer(buf: var openArray[char]) =
for i in 0..buf.len-1:
buf[i] = chr(i)

Expand Down
4 changes: 2 additions & 2 deletions tests/overload/toverload_various.nim
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ proc init*[T](hmctx: HMAC[T], key: ptr byte, ulen: uint) =
const sizeBlock = hmctx.sizeBlock
echo sizeBlock

proc hmac*[A, B](HashType: typedesc, key: openarray[A],
data: openarray[B]) =
proc hmac*[A, B](HashType: typedesc, key: openArray[A],
data: openArray[B]) =
var ctx: HMAC[HashType]
ctx.init(nil, 0)

Expand Down
Loading