init checks and 'out' parameters (#14521)

* I don't care about observable stores
* enforce explicit initializations
* cleaner code for the stdlib
* stdlib: use explicit initializations
* make tests green
* algorithm.nim: set result explicitly
* remove out parameters and bring the PR into a mergable state
* updated the changelog
This commit is contained in:
Andreas Rumpf 2020-06-23 10:53:57 +02:00 • committed by GitHub
commit da29222f86
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
53 changed files with 355 additions and 257 deletions

View file

@ -6,8 +6,8 @@ discard """
const expected = """
tassert_c.nim(35) tassert_c
tassert_c.nim(34) foo
assertions.nim(29) failedAssertImpl
assertions.nim(22) raiseAssert
assertions.nim(30) failedAssertImpl
assertions.nim(23) raiseAssert
fatal.nim(49) sysFatal"""
proc tmatch(x, p: string): bool =
@ -36,4 +36,5 @@ try:
except AssertionDefect:
let e = getCurrentException()
let trace = e.getStackTrace
if tmatch(trace, expected): echo true else: echo "wrong trace:\n" & trace
if tmatch(trace, expected): echo true
else: echo "wrong trace:\n" & trace

View file

@ -0,0 +1,28 @@
discard """
cmd: '''nim c --warningAsError[Uninit]:on --skipCfg --skipParentCfg $file'''
errormsg: "use explicit initialization of 'x' for clarity [Uninit]"
line: 24
disabled: "true"
"""
proc gah[T](x: out T) =
x = 3
proc main =
var a: array[2, int]
var x: int
gah(x)
a[0] = 3
a[x] = 3
echo x
main()
proc mainB =
var a: array[2, int]
var x: int
a[0] = 3
a[x] = 3
echo x
mainB()

View file

@ -1,5 +1,5 @@
discard """
nimout: "Warning: 'y' might not have been initialized [Uninit]"
nimout: "Warning: use explicit initialization of 'y' for clarity [Uninit]"
line:34
action: compile
"""