From 5a71c36d254d22515e5a96b6e3b217dacd64adbe Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Fri, 13 Dec 2024 22:04:49 +0800 Subject: [PATCH] fixes strictdefs warnings continue (#24520) (cherry picked from commit d2d810585c488b54c2da29a9a1ac6525bd4ff21e) --- compiler/sempass2.nim | 2 +- lib/system.nim | 2 +- lib/system/chcks.nim | 5 +++ lib/system/compilation.nim | 2 +- lib/system/repr_v2.nim | 2 + testament/categories.nim | 23 +++++------ testament/htmlgen.nim | 2 +- testament/lib/stdtest/netutils.nim | 2 +- testament/specs.nim | 10 ++--- testament/testament.nim | 47 +++++++++++++---------- testament/testament.nim.cfg | 2 + tests/alias/talias.nim | 7 ++-- tests/arc/dmodule.nim | 3 +- tests/arc/nim.cfg | 2 + tests/arc/t14383.nim | 3 +- tests/arc/t14472.nim | 3 +- tests/arc/t19364.nim | 1 + tests/arc/t19862.nim | 2 +- tests/arc/t22478.nim | 1 + tests/arc/t22787.nim | 4 +- tests/arc/t9650.nim | 1 + tests/arc/taliased_reassign.nim | 2 +- tests/arc/tamemfiles.nim | 3 ++ tests/arc/tarc_orc.nim | 2 + tests/arc/tarcmisc.nim | 17 +++++--- tests/arc/tcaseobj.nim | 3 +- tests/arc/tcaseobjcopy.nim | 3 +- tests/arc/tcursor_field_obj_constr.nim | 2 +- tests/arc/tcursor_on_localvar.nim | 2 + tests/arc/tcustomtrace.nim | 7 +++- tests/arc/tdeepcopy.nim | 6 +-- tests/arc/tdestroy_in_loopcond.nim | 1 + tests/arc/tdup.nim | 1 + tests/arc/tfuncobj.nim | 2 +- tests/arc/thamming_orc.nim | 2 +- tests/arc/thard_alignment.nim | 13 ++++--- tests/arc/thavlak_orc_stress.nim | 4 ++ tests/arc/tmarshal.nim | 2 +- tests/arc/tmove_regression.nim | 1 + tests/arc/tmovebug.nim | 2 + tests/arc/topt_cursor2.nim | 3 +- tests/arc/topt_no_cursor.nim | 4 +- tests/arc/topt_wasmoved_destroy_pairs.nim | 4 +- tests/arc/torcmisc.nim | 1 + tests/arc/trepr.nim | 2 +- tests/arc/trtree.nim | 19 +++++---- tests/arc/tshared_ptr_crash.nim | 1 + tests/arc/tweave.nim | 4 +- tests/arc/tweavecopy.nim | 4 +- 49 files changed, 152 insertions(+), 91 deletions(-) diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim index b151caf4be..b3fb3d91b2 100644 --- a/compiler/sempass2.nim +++ b/compiler/sempass2.nim @@ -1659,7 +1659,7 @@ proc trackProc*(c: PContext; s: PSym, body: PNode) = (t.config.selectedGC in {gcArc, gcOrc, gcAtomicArc} and (isClosure(typ.skipTypes(abstractInst)) or param.id in t.escapingParams)): createTypeBoundOps(t, typ, param.info) - if isOutParam(typ) and param.id notin t.init: + if isOutParam(typ) and param.id notin t.init and s.magic == mNone: message(g.config, param.info, warnProveInit, param.name.s) if not isEmptyType(s.typ.returnType) and diff --git a/lib/system.nim b/lib/system.nim index 4c78c4f3da..a79f26b4c7 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -2688,7 +2688,7 @@ proc locals*(): RootObj {.magic: "Plugin", noSideEffect.} = when hasAlloc and notJSnotNims: # XXX how to implement 'deepCopy' is an open problem. - proc deepCopy*[T](x: var T, y: T) {.noSideEffect, magic: "DeepCopy".} = + proc deepCopy*[T](x: out T, y: T) {.noSideEffect, magic: "DeepCopy".} = ## Performs a deep copy of `y` and copies it into `x`. ## ## This is also used by the code generator diff --git a/lib/system/chcks.nim b/lib/system/chcks.nim index b488559644..1a7d7f0a90 100644 --- a/lib/system/chcks.nim +++ b/lib/system/chcks.nim @@ -73,30 +73,35 @@ proc chckIndx(i, a, b: int): int = if i >= a and i <= b: return i else: + result = 0 raiseIndexError3(i, a, b) proc chckRange(i, a, b: int): int = if i >= a and i <= b: return i else: + result = 0 raiseRangeError(i) proc chckRange64(i, a, b: int64): int64 {.compilerproc.} = if i >= a and i <= b: return i else: + result = 0 raiseRangeError(i) proc chckRangeU(i, a, b: uint64): uint64 {.compilerproc.} = if i >= a and i <= b: return i else: + result = 0 sysFatal(RangeDefect, "value out of range") proc chckRangeF(x, a, b: float): float = if x >= a and x <= b: return x else: + result = 0.0 when hostOS == "standalone": sysFatal(RangeDefect, "value out of range") else: diff --git a/lib/system/compilation.nim b/lib/system/compilation.nim index cdb976ed53..8af27febbc 100644 --- a/lib/system/compilation.nim +++ b/lib/system/compilation.nim @@ -203,7 +203,7 @@ proc staticExec*(command: string, input = "", cache = ""): string {. ## ``` proc gorgeEx*(command: string, input = "", cache = ""): tuple[output: string, - exitCode: int] = + exitCode: int] {.noinit.} = ## Similar to `gorge <#gorge,string,string,string>`_ but also returns the ## precious exit code. discard diff --git a/lib/system/repr_v2.nim b/lib/system/repr_v2.nim index d2aef536c6..1c21c06470 100644 --- a/lib/system/repr_v2.nim +++ b/lib/system/repr_v2.nim @@ -140,6 +140,8 @@ proc repr*[T: tuple|object](x: T): string {.noSideEffect, raises: [].} = ## ``` when T is object: result = $typeof(x) + else: + result = "" reprObject(result, x) proc repr*[T](x: ref T | ptr T): string {.noSideEffect, raises: [].} = diff --git a/testament/categories.nim b/testament/categories.nim index 4704301b5f..ee2da5bb8d 100644 --- a/testament/categories.nim +++ b/testament/categories.nim @@ -347,7 +347,7 @@ proc compileExample(r: var TResults, pattern, options: string, cat: Category) = testSpec r, test proc testStdlib(r: var TResults, pattern, options: string, cat: Category) = - var files: seq[string] + var files: seq[string] = @[] proc isValid(file: string): bool = for dir in parentDirs(file, inclusive = false): @@ -383,11 +383,13 @@ proc testStdlib(r: var TResults, pattern, options: string, cat: Category) = # ----------------------------- nimble ---------------------------------------- proc listPackagesAll(): seq[NimblePackage] = + result = @[] var nimbleDir = getEnv("NIMBLE_DIR") if nimbleDir.len == 0: nimbleDir = getHomeDir() / ".nimble" let packageIndex = nimbleDir / "packages_official.json" let packageList = parseFile(packageIndex) proc findPackage(name: string): JsonNode = + result = nil for a in packageList: if a["name"].str == name: return a for pkg in important_packages.packages.items: @@ -411,17 +413,15 @@ proc listPackages(packageFilter: string): seq[NimblePackage] = elif testamentData0.testamentNumBatch == 0: result = pkgs else: + result = @[] let pkgs2 = pkgs.filterIt(not it.allowFailure) for i in 0.. 0: myself &= " " & quoteShell("--skipFrom:" & skipFrom) - var cats: seq[string] + var cats: seq[string] = @[] let rest = if p.cmdLineRest.len > 0: " " & p.cmdLineRest else: "" for kind, dir in walkDir(testsDir): assert testsDir.startsWith(testsDir) @@ -780,7 +785,7 @@ proc main() = cats.add AdditionalCategories if useMegatest: cats.add MegaTestCat - var cmds: seq[string] + var cmds: seq[string] = @[] for cat in cats: let runtype = if useMegatest: " pcat " else: " cat " cmds.add(myself & runtype & quoteShell(cat) & rest) diff --git a/testament/testament.nim.cfg b/testament/testament.nim.cfg index c97284129e..0ccfd90480 100644 --- a/testament/testament.nim.cfg +++ b/testament/testament.nim.cfg @@ -4,3 +4,5 @@ path = "$nim" # For compiler/nodejs -d:ssl # For azure # my SSL doesn't have this feature and I don't care: -d:nimDisableCertificateValidation +--warningAserror:ProveInit +--warningAserror:Uninit \ No newline at end of file diff --git a/tests/alias/talias.nim b/tests/alias/talias.nim index a8f1b0dd0a..9fd57326d9 100644 --- a/tests/alias/talias.nim +++ b/tests/alias/talias.nim @@ -31,10 +31,11 @@ type se: seq[TA] proc p(param1, param2: TC, param3: var TC): TC = + result = TC() var - local: TC - plocal: ptr TC - plocal2: ptr TA + local: TC = default(TC) + plocal: ptr TC = nil + plocal2: ptr TA = nil local.arr <| local local.arr[0] <| local diff --git a/tests/arc/dmodule.nim b/tests/arc/dmodule.nim index 455ec70846..c0e9fd07e4 100644 --- a/tests/arc/dmodule.nim +++ b/tests/arc/dmodule.nim @@ -16,8 +16,9 @@ proc `$`*(a: MinValue): string {.inline.} = result = "hello" for i in a.symbols: result = "hello" - else: discard + else: result = "" proc parseMinValue*(): MinValue = # or this echo + result = MinValue() echo result diff --git a/tests/arc/nim.cfg b/tests/arc/nim.cfg index 7c148b797c..a3ba78cdc5 100644 --- a/tests/arc/nim.cfg +++ b/tests/arc/nim.cfg @@ -1 +1,3 @@ --sinkInference:on +--warningAserror:ProveInit +--warningAserror:Uninit \ No newline at end of file diff --git a/tests/arc/t14383.nim b/tests/arc/t14383.nim index 96b5051669..cbad2372e2 100644 --- a/tests/arc/t14383.nim +++ b/tests/arc/t14383.nim @@ -198,6 +198,7 @@ proc allocCpuStorage[T](s: var CpuStorage[T], size: int) = s.size = size proc newTensor[T](size: int): Tensor[T] = + result = default(Tensor[T]) allocCpuStorage(result.buf, size) proc `[]`[T](t: Tensor[T], idx: int): T = t.buf.raw_buffer[idx] @@ -209,7 +210,7 @@ proc toTensor[T](s: seq[T]): Tensor[T] = result[i] = x proc main2() = - var t: TestObject + var t: TestObject = TestObject() t.x = toTensor(@[1.0, 2, 3, 4]) t.x = t.x doAssert(t.x.buf != nil) # self-assignment above should be eliminated diff --git a/tests/arc/t14472.nim b/tests/arc/t14472.nim index 4ef6611617..bb6897f2df 100644 --- a/tests/arc/t14472.nim +++ b/tests/arc/t14472.nim @@ -15,7 +15,8 @@ type meshes*: seq[Mesh] proc bork() : ImportedScene = - var mats: seq[ImportMaterial] + result = ImportedScene() + var mats: seq[ImportMaterial] = @[] setLen(mats, 1) add(result.meshes, Mesh(material: mats[0])) diff --git a/tests/arc/t19364.nim b/tests/arc/t19364.nim index f520f32916..993c76f5ee 100644 --- a/tests/arc/t19364.nim +++ b/tests/arc/t19364.nim @@ -19,6 +19,7 @@ c_cursor = tmpTuple_cursor[2] func fooLeaks(refTuple: tuple[a, b, c: seq[float]]): float = + result = 0.0 let (a, b, c) = refTuple let refset = (a: newSeq[float](25_000_000), diff --git a/tests/arc/t19862.nim b/tests/arc/t19862.nim index 6d3f576926..27eb134bb5 100644 --- a/tests/arc/t19862.nim +++ b/tests/arc/t19862.nim @@ -9,7 +9,7 @@ type NewString = object proc len(s: NewString): int = 10 -converter toNewString(x: WideCStringObj): NewString = discard +converter toNewString(x: WideCStringObj): NewString = default(NewString) let w = newWideCString("test") doAssert len(w) == 4 diff --git a/tests/arc/t22478.nim b/tests/arc/t22478.nim index 5373fa1616..96e5ca0007 100644 --- a/tests/arc/t22478.nim +++ b/tests/arc/t22478.nim @@ -41,6 +41,7 @@ proc pushScoped*[T](metric: string, blk: WithTimeCallback[T]): T {.gcsafe.} = # demo code discard pushScoped[int]("test.message") do (data: var JsonNode) -> int: + result = 0 data["test"] = %*{ "nested": "v1" } \ No newline at end of file diff --git a/tests/arc/t22787.nim b/tests/arc/t22787.nim index 5840a984b9..1647d3e2e4 100644 --- a/tests/arc/t22787.nim +++ b/tests/arc/t22787.nim @@ -5,14 +5,14 @@ discard """ import std/assertions proc foo = - var s:seq[string] + var s:seq[string] = @[] var res = "" for i in 0..3: s.add ("test" & $i) s.add ("test" & $i) - var lastname:string + var lastname:string = "" for i in s: var name = i[0..4] diff --git a/tests/arc/t9650.nim b/tests/arc/t9650.nim index a8182db68c..e6daa38d65 100644 --- a/tests/arc/t9650.nim +++ b/tests/arc/t9650.nim @@ -40,6 +40,7 @@ proc `=sink`*[T](dest: var SharedPtr[T], src: SharedPtr[T]) = proc newSharedPtr*[T](val: sink T): SharedPtr[T] = + result = default(SharedPtr[T]) result.val = cast[type(result.val)](alloc(sizeof(result.val[]))) reset(result.val[]) result.val.atomicCounter = 1 diff --git a/tests/arc/taliased_reassign.nim b/tests/arc/taliased_reassign.nim index 5563fae8c4..b472b7aa0f 100644 --- a/tests/arc/taliased_reassign.nim +++ b/tests/arc/taliased_reassign.nim @@ -26,7 +26,7 @@ proc `+.`[T](t1, t2: Tensor[T]): Tensor[T] = proc toTensor*[T](a: sink seq[T]): Tensor[T] = ## This breaks it: Using `T` instead makes it work type U = typeof(a[0]) - var t: Tensor[U] # Tensor[T] works + var t: Tensor[U] = default(Tensor[U]) # Tensor[T] works t.buf = a result = t diff --git a/tests/arc/tamemfiles.nim b/tests/arc/tamemfiles.nim index 97deb489f2..29533b215c 100644 --- a/tests/arc/tamemfiles.nim +++ b/tests/arc/tamemfiles.nim @@ -31,6 +31,7 @@ proc `+!`*(p: pointer, i: uint64): pointer {.inline.} = proc charEq(x, c: char): bool {.inline.} = x == c proc initSplitr*(delim: string): Splitr = + result = default(Splitr) if delim == "white": #User can use any other permutation if needed result.repeat = true result.chrDlm = ' ' @@ -81,6 +82,7 @@ template defSplit[T](slc: T, fs: var seq[MemSlice], n: int, repeat: bool, proc msplit*(s: MemSlice, fs: var seq[MemSlice], sep=' ', n=0, repeat=false): int = + result = 0 defSplit(s, fs, n, repeat, sep, cmemchr, charEq) proc split*(s: Splitr, line: MemSlice, cols: var seq[MemSlice], @@ -92,6 +94,7 @@ proc split*(s: Splitr, line: MemSlice, cols: var seq[MemSlice], # to mask the arc problem, as does simplifying `Table` to `seq[char]`. proc load(path: string, delim=" "): Table[MemSlice, seq[char]] = + result = default(Table[MemSlice, seq[char]]) let f = memfiles.open(path) let splitr = initSplitr(delim) var cols: seq[MemSlice] = @[ ] # re-used seq buffer diff --git a/tests/arc/tarc_orc.nim b/tests/arc/tarc_orc.nim index f2c7de2fca..790511314c 100644 --- a/tests/arc/tarc_orc.nim +++ b/tests/arc/tarc_orc.nim @@ -17,6 +17,7 @@ block: private: PrivateKey proc initKeyPair(): KeyPair = + result = KeyPair() ed25519_create_keypair(result.public.addr, result.private.addr) let keys = initKeyPair() @@ -52,6 +53,7 @@ type Obj = tuple arr: seq[int] proc bug(): seq[Obj] = + result = @[] result.add (value: 0, arr: @[]) result[^1].value = 1 result[^1].arr.add 1 diff --git a/tests/arc/tarcmisc.nim b/tests/arc/tarcmisc.nim index d9cbb46403..6b8fc3b06f 100644 --- a/tests/arc/tarcmisc.nim +++ b/tests/arc/tarcmisc.nim @@ -100,6 +100,7 @@ proc `=sink`*(m: var MyObj, m2: MyObj) = m.data = m2.data proc newMyObj(len: int): MyObj = + result = MyObj() result.len = len result.data = cast[ptr UncheckedArray[float]](allocShared(sizeof(float) * len)) @@ -117,6 +118,8 @@ proc takeSink(x: sink string): bool = true proc b(x: sink string): string = if takeSink(x): return x & "abc" + else: + result = "" proc bbb(inp: string) = let y = inp & "xyz" @@ -267,11 +270,11 @@ type x: string proc bug14495 = - var owners: seq[Gah] + var owners: seq[Gah] = @[] for i in 0..10: owners.add Gah(x: $i) - var x: seq[Gah] + var x: seq[Gah] = @[] for i in 0..10: x.add owners[i] @@ -602,7 +605,7 @@ block: # bug #19857 doAssert v.kind == VFloat case v.kind of VFloat: result = v.fnum - else: discard + else: result = 0.0 proc foo() = @@ -611,6 +614,7 @@ block: # bug #19857 # works: #result = Value(kind: VFloat, fnum: fuck["field_that_does_not_exist"].float) # broken: + result = Value() discard "actuall runs!" let t = fuck["field_that_does_not_exist"] echo "never runs, but we crash after! ", t @@ -638,7 +642,7 @@ method process*(self: App): Option[Event] {.base.} = # bug #21617 type Test2 = ref object of RootObj -method bug(t: Test2): seq[float] {.base.} = discard +method bug(t: Test2): seq[float] {.base.} = result = @[] block: # bug #22664 type @@ -674,6 +678,7 @@ block: # bug #19250 Bar[T](err: err) proc foo(): Foo[char] = + result = Foo[char]() result.run = proc(): Bar[char] = # works # result = Bar[char](err: proc(): string = "x") @@ -681,6 +686,7 @@ block: # bug #19250 result = bar[char](proc(): string = "x") proc bug[T](fs: Foo[T]): Foo[T] = + result = Foo[T]() result.run = proc(): Bar[T] = let res = fs.run() @@ -688,10 +694,11 @@ block: # bug #19250 # var errors = @[res.err] # not work - var errors: seq[proc(): string] + var errors: seq[proc(): string] = @[] errors.add res.err return bar[T] do () -> string: + result = "" for err in errors: result.add res.err() diff --git a/tests/arc/tcaseobj.nim b/tests/arc/tcaseobj.nim index 3499f5c1e3..0b085b6cc1 100644 --- a/tests/arc/tcaseobj.nim +++ b/tests/arc/tcaseobj.nim @@ -166,7 +166,7 @@ type x2: string proc test_myobject = - var x: MyObject + var x: MyObject = MyObject() x.x1 = "x1" x.x2 = "x2" x.y1 = "ljhkjhkjh" @@ -213,6 +213,7 @@ type error*: string proc init(): RocksDBResult[string] = + result = default(RocksDBResult[string]) {.cast(uncheckedAssign).}: result.ok = true result.value = "ok" diff --git a/tests/arc/tcaseobjcopy.nim b/tests/arc/tcaseobjcopy.nim index fb26a49736..534583865d 100644 --- a/tests/arc/tcaseobjcopy.nim +++ b/tests/arc/tcaseobjcopy.nim @@ -165,7 +165,7 @@ type x2: string proc test_myobject = - var x: MyObject + var x: MyObject = MyObject() x.x1 = "x1" x.x2 = "x2" x.y1 = "ljhkjhkjh" @@ -211,6 +211,7 @@ type error*: string proc init(): RocksDBResult[string] = + result = default(RocksDBResult[string]) {.cast(uncheckedAssign).}: result.ok = true result.value = "ok" diff --git a/tests/arc/tcursor_field_obj_constr.nim b/tests/arc/tcursor_field_obj_constr.nim index b87f734bd5..6cfddd8b1f 100644 --- a/tests/arc/tcursor_field_obj_constr.nim +++ b/tests/arc/tcursor_field_obj_constr.nim @@ -33,7 +33,7 @@ proc addEdge(self: Graph; source, neighbor: Node) = source.neighbors.add(Edge(neighbor: neighbor)) proc main = - var graph: Graph + var graph: Graph = Graph() let nodeA = graph.addNode("a") let nodeB = graph.addNode("b") let nodeC = graph.addNode("c") diff --git a/tests/arc/tcursor_on_localvar.nim b/tests/arc/tcursor_on_localvar.nim index 0f53c5efa5..93d0363d00 100644 --- a/tests/arc/tcursor_on_localvar.nim +++ b/tests/arc/tcursor_on_localvar.nim @@ -38,12 +38,14 @@ proc add*(self: Config, param, value, section: string) {.nosinks.} = # ---------------------------------------------------------------------------------------------------------------------- proc sections*(self: Config): seq[string] = + result = @[] for i in self.table.keys: let s = if i == defaultSection: "" else: i result.add(s) # ---------------------------------------------------------------------------------------------------------------------- proc params*(self: Config, section: string): seq[string] = + result = @[] let s = if section == "": defaultSection else: section if self.table.contains(s): diff --git a/tests/arc/tcustomtrace.nim b/tests/arc/tcustomtrace.nim index 5e0ecfb248..ec978822ea 100644 --- a/tests/arc/tcustomtrace.nim +++ b/tests/arc/tcustomtrace.nim @@ -125,9 +125,12 @@ template `[]=`*[T](x: myseq[T]; i: Natural; y: T) = x.data[i] = y proc createSeq*[T](elems: varargs[T]): myseq[T] = - result.cap = max(elems.len, 2) - result.len = elems.len + result = myseq[T]( + cap: max(elems.len, 2), + len: elems.len) + result.data = cast[type(result.data)](alloc0(result.cap * sizeof(T))) + inc allocCount when supportsCopyMem(T): copyMem(result.data, addr(elems[0]), result.cap * sizeof(T)) diff --git a/tests/arc/tdeepcopy.nim b/tests/arc/tdeepcopy.nim index 91d93aa286..274d042c00 100644 --- a/tests/arc/tdeepcopy.nim +++ b/tests/arc/tdeepcopy.nim @@ -31,10 +31,10 @@ type value: int proc mainB = - var x: PBinaryTree + var x: PBinaryTree = nil deepCopy(x, PBinaryTree(ri: PBinaryTree(le: PBinaryTree(value: 13)))) - var y: string + var y: string = "" deepCopy y, "abc" echo x.ri.le.value, " ", y @@ -55,7 +55,7 @@ proc `=deepCopy`[T](b: ref Bar[T]): ref Bar[T] = echo "called deepCopy for something else" proc main = - var dummy, c: ref Bar[int] + var dummy, c: ref Bar[int] = nil new(dummy) dummy.x = 44 diff --git a/tests/arc/tdestroy_in_loopcond.nim b/tests/arc/tdestroy_in_loopcond.nim index 62532664d8..ea1b4c13ca 100644 --- a/tests/arc/tdestroy_in_loopcond.nim +++ b/tests/arc/tdestroy_in_loopcond.nim @@ -41,6 +41,7 @@ proc newFuture(s: string): Future = var q: HeapQueue[tuple[finishAt: int64, fut: Future]] proc sleep(f: int64): Future = + result = nil q.push (finishAt: f, fut: newFuture("async-sleep")) proc processTimers = diff --git a/tests/arc/tdup.nim b/tests/arc/tdup.nim index 61f262a681..c8d97772d5 100644 --- a/tests/arc/tdup.nim +++ b/tests/arc/tdup.nim @@ -35,6 +35,7 @@ type id: ptr int proc `=dup`(x: RefCustom): RefCustom = + result = RefCustom() result.id = x.id proc inc(x: sink Ref) = diff --git a/tests/arc/tfuncobj.nim b/tests/arc/tfuncobj.nim index 50cd9425e1..f5214ee81b 100644 --- a/tests/arc/tfuncobj.nim +++ b/tests/arc/tfuncobj.nim @@ -19,7 +19,7 @@ proc `=copy`(x: var FuncObj, y: FuncObj) {.error.} # bug #18433 proc main = - var fs: seq[FuncObj] + var fs: seq[FuncObj] = @[] proc wrap(p: proc()) = proc closeOver() = p() diff --git a/tests/arc/thamming_orc.nim b/tests/arc/thamming_orc.nim index 777efb38e4..f008748858 100644 --- a/tests/arc/thamming_orc.nim +++ b/tests/arc/thamming_orc.nim @@ -140,7 +140,7 @@ proc main = "Algorithmic error finding first 20 Hamming numbers!!!" when not defined(trace20): - var lsth: TriVal + var lsth: TriVal = default(TriVal) for h in hammings(200): lsth = h doAssert $lsth.convertTriVal2BigInt == "16200", "Algorithmic error finding 200th Hamming number!!!" diff --git a/tests/arc/thard_alignment.nim b/tests/arc/thard_alignment.nim index 30cfddb055..b4c00b94e3 100644 --- a/tests/arc/thard_alignment.nim +++ b/tests/arc/thard_alignment.nim @@ -102,25 +102,26 @@ for i in 0..1000: proc lambdaTest2(a: MyAligned, z: ref MyAligned): auto = - var x1: MyAligned + var x1: MyAligned = default(MyAligned) x1.a = a.a + z.a - var x2: MyAligned + var x2: MyAligned = default(MyAligned) x2.a = a.a - z.a let capturingLambda = proc(x: MyAligned): MyAligned = - var cc: MyAligned - var bb: MyAligned + result = default(MyAligned) + var cc: MyAligned = default(MyAligned) + var bb: MyAligned = default(MyAligned) isAlignedCheck(x1.addr, MyAligned.alignOf) isAlignedCheck(x2.addr, MyAligned.alignOf) isAlignedCheck(cc.addr, MyAligned.alignOf) isAlignedCheck(bb.addr, MyAligned.alignOf) isAlignedCheck(z, MyAligned.alignOf) - + cc.a = x1.a + x1.a + z.a bb.a = x2.a - z.a isAlignedCheck(result.addr, MyAligned.alignOf) result.a = cc.a + bb.a + x2.a - + return capturingLambda diff --git a/tests/arc/thavlak_orc_stress.nim b/tests/arc/thavlak_orc_stress.nim index 862e1a0978..ea09e2f554 100644 --- a/tests/arc/thavlak_orc_stress.nim +++ b/tests/arc/thavlak_orc_stress.nim @@ -34,6 +34,7 @@ type startNode: ref BasicBlock proc newCfg(): Cfg = + result = Cfg() result.basicBlockMap = initTable[int, ref BasicBlock]() result.edgeList = newSeq[BasicBlockEdge]() @@ -120,6 +121,7 @@ proc addLoop(self: var Lsg, l: ref SimpleLoop) = self.loops.add l proc newLsg(): Lsg = + result = Lsg() result.loops = newSeq[ref SimpleLoop]() result.root = result.createNewLoop() result.root.setNestingLevel(0) @@ -182,6 +184,7 @@ type lsg: Lsg proc newHavlakLoopFinder(cfg: sink Cfg, lsg: sink Lsg): HavlakLoopFinder = + result = HavlakLoopFinder() result.cfg = cfg result.lsg = lsg @@ -366,6 +369,7 @@ type lsg: Lsg proc newLoopTesterApp(): LoopTesterApp = + result = LoopTesterApp() result.cfg = newCfg() result.lsg = newLsg() diff --git a/tests/arc/tmarshal.nim b/tests/arc/tmarshal.nim index f7ec6e2c58..bde99ce550 100644 --- a/tests/arc/tmarshal.nim +++ b/tests/arc/tmarshal.nim @@ -55,7 +55,7 @@ proc buildList(): PNode = result.prev.prev = result.next proc blockB = - var test3: TestObj + var test3: TestObj = TestObj() test3.test = 42 test3.test2 = blah testit(test3) diff --git a/tests/arc/tmove_regression.nim b/tests/arc/tmove_regression.nim index 7d9a867c39..fb9472d147 100644 --- a/tests/arc/tmove_regression.nim +++ b/tests/arc/tmove_regression.nim @@ -10,6 +10,7 @@ discard """ import std / [os, strutils] proc finOp2(path, name: string): (string, File) = # Find & open FIRST `name` + result = default((string, File)) var current = path while true: if current.isRootDir: break # <- current=="" => current.isRootDir diff --git a/tests/arc/tmovebug.nim b/tests/arc/tmovebug.nim index 8ad7c955ce..cc46dec699 100644 --- a/tests/arc/tmovebug.nim +++ b/tests/arc/tmovebug.nim @@ -786,6 +786,7 @@ main3() # misc proc smoltest(x: bool): bool = + result = false while true: if true: return x @@ -832,6 +833,7 @@ proc convoluted = let _ = (; var val1: string; if true: val1 = "22" + else: val1 = "" true ) diff --git a/tests/arc/topt_cursor2.nim b/tests/arc/topt_cursor2.nim index 4b566ed24e..ab13893d98 100644 --- a/tests/arc/topt_cursor2.nim +++ b/tests/arc/topt_cursor2.nim @@ -22,6 +22,7 @@ method `$`(token: Paragraph): string = if token.children.head == nil: result = "" else: + result = "" for c in token.children: result.add $c @@ -69,7 +70,7 @@ type holder = object contents: outer proc main() = - var t: holder + var t: holder = holder() t.contents = newOuter() main() diff --git a/tests/arc/topt_no_cursor.nim b/tests/arc/topt_no_cursor.nim index 0a4984a690..9d59fc66c2 100644 --- a/tests/arc/topt_no_cursor.nim +++ b/tests/arc/topt_no_cursor.nim @@ -40,6 +40,7 @@ var lvalue lnext tmpTupleAsgn +result = default(Maybe) lresult = @[123] tmpTupleAsgn = ( let blitTmp = lresult @@ -227,6 +228,7 @@ type value: seq[int] proc p1(): Maybe = + result = default(Maybe) let lresult = @[123] var lvalue: seq[int] var lnext: string @@ -248,7 +250,7 @@ proc tt(x: KeyValue) = echo a proc encodedQuery = - var query: seq[KeyValue] + var query: seq[KeyValue] = @[] query.add (key: @[1], val: @[2]) for elem in query: diff --git a/tests/arc/topt_wasmoved_destroy_pairs.nim b/tests/arc/topt_wasmoved_destroy_pairs.nim index c96340a30d..afca4ce0c3 100644 --- a/tests/arc/topt_wasmoved_destroy_pairs.nim +++ b/tests/arc/topt_wasmoved_destroy_pairs.nim @@ -64,7 +64,7 @@ proc f(): seq[int] = @[1, 2, 3] proc main(cond: bool) = - var a, b: seq[seq[int]] + var a, b: seq[seq[int]] = @[] var x = f() if cond: a.add x @@ -78,7 +78,7 @@ main(false) proc tfor(cond: bool) = - var a, b: seq[seq[int]] + var a, b: seq[seq[int]] = @[] var x = f() diff --git a/tests/arc/torcmisc.nim b/tests/arc/torcmisc.nim index e41ad7c773..fc0eaf2ff7 100644 --- a/tests/arc/torcmisc.nim +++ b/tests/arc/torcmisc.nim @@ -56,6 +56,7 @@ type peers*: Table[PeerID, PubSubPeer] proc getOrCreatePeer*(myParam: PubSub, peerId: PeerID, protos: seq[string]): PubSubPeer = + result = nil myParam.peers.withValue(peerId, peer): return peer[] diff --git a/tests/arc/trepr.nim b/tests/arc/trepr.nim index abf28330a3..c22c06adef 100644 --- a/tests/arc/trepr.nim +++ b/tests/arc/trepr.nim @@ -31,7 +31,7 @@ proc myproc2(t: MyType) = echo repr(x) proc myproc3(t: MyType) = - var x: TableRef[string, t] + var x: TableRef[string, t] = nil echo repr(x) diff --git a/tests/arc/trtree.nim b/tests/arc/trtree.nim index 683403a626..8b5ba3a6fa 100644 --- a/tests/arc/trtree.nim +++ b/tests/arc/trtree.nim @@ -72,7 +72,7 @@ proc newRStarTree*[M, D: Dim; RT, LT](minFill: range[30 .. 50] = 40): RStarTree[ result.root = newLeaf[M, D, RT, LT]() proc center(r: Box): auto =#BoxCenter[r.len, typeof(r[0].a)] = - var res: BoxCenter[r.len, typeof(r[0].a)] + var res = default(BoxCenter[r.len, typeof(r[0].a)]) for i in 0 .. r.high: when r[0].a is SomeInteger: res[i] = (r[i].a + r[i].b) div 2 @@ -82,7 +82,7 @@ proc center(r: Box): auto =#BoxCenter[r.len, typeof(r[0].a)] = return res proc distance(c1, c2: BoxCenter): auto = - var res: typeof(c1[0]) + var res: typeof(c1[0]) = default(typeof(c1[0])) for i in 0 .. c1.high: res += (c1[i] - c2[i]) * (c1[i] - c2[i]) return res @@ -94,6 +94,7 @@ proc overlap(r1, r2: Box): auto = if result <= 0: return 0 proc union(r1, r2: Box): Box = + result = default(Box) for i in 0 .. r1.high: result[i].a = min(r1[i].a, r2[i].a) result[i].b = max(r1[i].b, r2[i].b) @@ -178,7 +179,7 @@ proc chooseSubtree[M, D: Dim; RT, LT](t: RTree[M, D, RT, LT]; b: Box[D, RT]; lev return it proc pickSeeds[M, D: Dim; RT, LT](t: RTree[M, D, RT, LT]; n: Node[M, D, RT, LT] | Leaf[M, D, RT, LT]; bx: Box[D, RT]): (int, int) = - var i0, j0: int + var i0, j0: int = 0 var bi, bj: typeof(bx) var largestWaste = typeof(bx[0].a).low for i in -1 .. n.a.high: @@ -198,6 +199,7 @@ proc pickSeeds[M, D: Dim; RT, LT](t: RTree[M, D, RT, LT]; n: Node[M, D, RT, LT] return (i0, j0) proc pickNext[M, D: Dim; RT, LT](t: RTree[M, D, RT, LT]; n0, n1, n2: Node[M, D, RT, LT] | Leaf[M, D, RT, LT]; b1, b2: Box[D, RT]): int = + result = 0 let a1 = area(b1) let a2 = area(b2) var d = typeof(a1).low @@ -227,7 +229,7 @@ proc rstarSplit[M, D: Dim; RT, LT](t: RStarTree[M, D, RT, LT]; n: var Node[M, D, var lx = lx when n is Node[M, D, RT, LT]: lx.n.parent = n - var lxbest: typeof(lx) + var lxbest: typeof(lx) = default(typeof(lx)) var m0 = lx.b[0].a.typeof.high for d2 in 0 ..< 2 * D: let d = d2 div 2 @@ -361,7 +363,7 @@ proc adjustTree[M, D: Dim; RT, LT](t: RTree[M, D, RT, LT]; l, ll: H[M, D, RT, LT var i = 0 while p.a[i].n != n: inc(i) - var b: typeof(p.a[0].b) + var b: typeof(p.a[0].b) = default(typeof(p.a[0].b)) if n of Leaf[M, D, RT, LT]: when false:#if likely(nn.isNil): # no performance gain b = union(p.a[i].b, Leaf[M, D, RT, LT](n).a[n.numEntries - 1].b) @@ -429,7 +431,7 @@ proc rsinsert[M, D: Dim; RT, LT](t: RStarTree[M, D, RT, LT]; leaf: N[M, D, RT, L proc reInsert[M, D: Dim; RT, LT](t: RStarTree[M, D, RT, LT]; n: var Node[M, D, RT, LT] | var Leaf[M, D, RT, LT]; lx: L[D, RT, LT] | N[M, D, RT, LT]) = type NL = typeof(lx) var lx = lx - var buf: typeof(n.a) + var buf: typeof(n.a) = default(typeof(n.a)) let p = Node[M, D, RT, LT](n.parent) var i = 0 while p.a[i].n != n: @@ -510,7 +512,7 @@ proc findLeaf[M, D: Dim; RT, LT](t: RTree[M, D, RT, LT]; leaf: L[D, RT, LT]): Le proc condenseTree[M, D: Dim; RT, LT](t: RTree[M, D, RT, LT]; leaf: Leaf[M, D, RT, LT]) = var n: H[M, D, RT, LT] = leaf var q = newSeq[H[M, D, RT, LT]]() - var b: typeof(leaf.a[0].b) + var b: typeof(leaf.a[0].b) = default(typeof(leaf.a[0].b)) while n != t.root: let p = Node[M, D, RT, LT](n.parent) var i = 0 @@ -592,6 +594,7 @@ proc rseq_search(rs: RSeq; rse: RSE): seq[int] = result.add(i.l) proc rseq_delete(rs: var RSeq; rse: RSE): bool = + result = false for i in 0 .. rs.high: if rs[i] == rse: #rs.delete(i) @@ -602,7 +605,7 @@ proc rseq_delete(rs: var RSeq; rse: RSE): bool = import random, algorithm proc test(n: int) = - var b: Box[2, int] + var b: Box[2, int] = default(Box[2, int]) echo center(b) var x1, x2, y1, y2: int var t = newRStarTree[8, 2, int, int]() diff --git a/tests/arc/tshared_ptr_crash.nim b/tests/arc/tshared_ptr_crash.nim index 1794834dbb..9b34e7c106 100644 --- a/tests/arc/tshared_ptr_crash.nim +++ b/tests/arc/tshared_ptr_crash.nim @@ -26,6 +26,7 @@ proc `=copy`*[T](dest: var SharedPtr[T], src: SharedPtr[T]) = dest.val = src.val proc newSharedPtr*[T](val: sink T): SharedPtr[T] {.nodestroy.} = + result = SharedPtr[T]() result.val = cast[typeof(result.val)](allocShared(sizeof(result.val[]))) result.val.atomicCounter = 0 result.val.value = val diff --git a/tests/arc/tweave.nim b/tests/arc/tweave.nim index 1c60ac4030..57edc9712f 100644 --- a/tests/arc/tweave.nim +++ b/tests/arc/tweave.nim @@ -118,7 +118,7 @@ when isMainModule: # chan <- 53 # chan <- 64 Worker(Receiver): - var val: int + var val: int = 0 for j in 0 ..< 10: args.chan[].recvLoop(val): # Busy loop, in prod we might want to yield the core/thread timeslice @@ -138,7 +138,7 @@ when isMainModule: proc main() = echo "Testing if 2 threads can send data" echo "-----------------------------------" - var threads: array[2, Thread[ThreadArgs]] + var threads: array[2, Thread[ThreadArgs]] = default(array[2, Thread[ThreadArgs]]) var chan = cast[ptr ChannelSPSCSingle](allocShared(MemBlockSize)) chan[].initialize(itemSize = sizeof(int)) diff --git a/tests/arc/tweavecopy.nim b/tests/arc/tweavecopy.nim index fc796b3525..561a8c2778 100644 --- a/tests/arc/tweavecopy.nim +++ b/tests/arc/tweavecopy.nim @@ -115,7 +115,7 @@ when isMainModule: # chan <- 53 # chan <- 64 Worker(Receiver): - var val: int + var val: int = 0 for j in 0 ..< 10: args.chan[].recvLoop(val): # Busy loop, in prod we might want to yield the core/thread timeslice @@ -135,7 +135,7 @@ when isMainModule: proc main() = echo "Testing if 2 threads can send data" echo "-----------------------------------" - var threads: array[2, Thread[ThreadArgs]] + var threads: array[2, Thread[ThreadArgs]] = default(array[2, Thread[ThreadArgs]]) var chan = cast[ptr ChannelSPSCSingle](allocShared(MemBlockSize)) chan[].initialize(itemSize = sizeof(int))