diff --git a/changelog.md b/changelog.md index 2e1795bab5..6cd0faf528 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,4 @@ -## v0.X.X - XX/XX/2018 +## v0.19.X - XX/XX/2018 ### Changes affecting backwards compatibility @@ -14,6 +14,9 @@ - Assignments that would "slice" an object into its supertype are now prevented at runtime. Use ``ref object`` with inheritance rather than ``object`` with inheritance to prevent this issue. +- The ``not nil`` type annotation now has to be enabled explicitly + via ``{.experimental: "notnil"}`` as we are still not pleased with how this + feature works with Nim's containers. #### Breaking changes in the standard library diff --git a/compiler/condsyms.nim b/compiler/condsyms.nim index b1d0ccc7a8..f8a75e68e3 100644 --- a/compiler/condsyms.nim +++ b/compiler/condsyms.nim @@ -116,3 +116,4 @@ proc initDefines*() = defineSymbol("nimVmEqIdent") defineSymbol("nimNoNil") defineSymbol("nimNoZeroTerminator") + defineSymbol("nimNotNil") diff --git a/compiler/options.nim b/compiler/options.nim index 9f56d3f180..5baaa1bfd5 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -109,7 +109,8 @@ type dotOperators, callOperator, parallel, - destructor + destructor, + notnil ConfigRef* = ref object ## eventually all global configuration should be moved here cppDefines*: HashSet[string] diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 1fc263617b..537319d66f 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -1389,6 +1389,8 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType = n.sons[2].kind == nkNilLit: result = freshType(result, prev) result.flags.incl(tfNotNil) + if notnil notin c.features: + localError(n.info, "enable the 'not nil' annotation with {.experimental: \"notnil\".}") else: localError(n.info, errGenerated, "invalid type") of 2: diff --git a/lib/system.nim b/lib/system.nim index 5c0970f853..0c8659fdaf 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -3223,7 +3223,7 @@ when not defined(JS): #and not defined(nimscript): when declared(initGC): initGC() when not defined(nimscript): - proc setControlCHook*(hook: proc () {.noconv.} not nil) + proc setControlCHook*(hook: proc () {.noconv.}) ## allows you to override the behaviour of your application when CTRL+C ## is pressed. Only one such hook is supported. diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim index afeab2b6c3..fb38948f7b 100644 --- a/lib/system/excpt.nim +++ b/lib/system/excpt.nim @@ -56,7 +56,7 @@ var # list of exception handlers # a global variable for the root of all try blocks currException {.threadvar.}: ref Exception - raise_counter {.threadvar.}: uint + raise_counter {.threadvar.}: uint gcFramePtr {.threadvar.}: GcFrame @@ -126,10 +126,10 @@ proc popCurrentExceptionEx(id: uint) {.compilerRtl.} = while cur != nil and cur.raise_id != id: prev = cur cur = cur.up - if cur == nil: + if cur == nil: showErrorMessage("popCurrentExceptionEx() exception was not found in the exception stack. Aborting...") quitOrDebug() - prev.up = cur.up + prev.up = cur.up # some platforms have native support for stack traces: const @@ -503,7 +503,7 @@ when not defined(noSignalHandler) and not defined(useNimRtl): registerSignalHandler() # call it in initialization section -proc setControlCHook(hook: proc () {.noconv.} not nil) = +proc setControlCHook(hook: proc () {.noconv.}) = # ugly cast, but should work on all architectures: type SignalHandler = proc (sign: cint) {.noconv, benign.} c_signal(SIGINT, cast[SignalHandler](hook)) diff --git a/tests/notnil/tmust_compile.nim b/tests/notnil/tmust_compile.nim index 10da154f00..a32c6c7ecd 100644 --- a/tests/notnil/tmust_compile.nim +++ b/tests/notnil/tmust_compile.nim @@ -3,6 +3,7 @@ discard """ """ # bug #6682 +{.experimental: "notnil".} type Fields = enum diff --git a/tests/notnil/tnotnil.nim b/tests/notnil/tnotnil.nim index f65634ed66..e392b155c6 100644 --- a/tests/notnil/tnotnil.nim +++ b/tests/notnil/tnotnil.nim @@ -2,7 +2,7 @@ discard """ line: 22 errormsg: "type mismatch" """ - +{.experimental: "notnil".} type PObj = ref TObj not nil TObj = object @@ -15,8 +15,8 @@ type proc p(x: string not nil): int = result = 45 -proc q(x: MyString) = nil -proc q2(x: string) = nil +proc q(x: MyString) = discard +proc q2(x: string) = discard q2(nil) q(nil) diff --git a/tests/notnil/tnotnil1.nim b/tests/notnil/tnotnil1.nim index 73472752c7..7f9d022958 100644 --- a/tests/notnil/tnotnil1.nim +++ b/tests/notnil/tnotnil1.nim @@ -4,7 +4,7 @@ discard """ """ import strutils - +{.experimental: "notnil".} type TObj = object @@ -18,13 +18,13 @@ proc q(s: superstring) = echo s proc p2() = - var a: string = "I am not nil" + var a: string = "I am not nil" q(a) # but this should and does not p2() proc q(x: pointer not nil) = - nil + discard proc p() = var x: pointer diff --git a/tests/notnil/tnotnil2.nim b/tests/notnil/tnotnil2.nim index bd6b8b6755..6ab7bf9519 100644 --- a/tests/notnil/tnotnil2.nim +++ b/tests/notnil/tnotnil2.nim @@ -4,7 +4,7 @@ discard """ """ import strutils - +{.experimental: "notnil".} type TObj = object diff --git a/tests/notnil/tnotnil3.nim b/tests/notnil/tnotnil3.nim index b7c7a811d1..31a4efef78 100644 --- a/tests/notnil/tnotnil3.nim +++ b/tests/notnil/tnotnil3.nim @@ -5,7 +5,7 @@ discard """ # bug #584 # Testprogram for 'not nil' check - +{.experimental: "notnil".} const testWithResult = true type diff --git a/tests/notnil/tnotnil4.nim b/tests/notnil/tnotnil4.nim index 2fa888357f..4fd169827d 100644 --- a/tests/notnil/tnotnil4.nim +++ b/tests/notnil/tnotnil4.nim @@ -2,6 +2,8 @@ discard "" type TObj = ref object +{.experimental: "notnil".} + proc check(a: TObj not nil) = echo repr(a) diff --git a/tests/notnil/tnotnil_in_generic.nim b/tests/notnil/tnotnil_in_generic.nim index 357ab2c7c7..89d20f1826 100644 --- a/tests/notnil/tnotnil_in_generic.nim +++ b/tests/notnil/tnotnil_in_generic.nim @@ -3,6 +3,7 @@ discard """ """ # bug #2216 +{.experimental: "notnil".} type A[T] = ref object diff --git a/tests/notnil/tnotnil_in_objconstr.nim b/tests/notnil/tnotnil_in_objconstr.nim index 7dce98c29f..d33709906b 100644 --- a/tests/notnil/tnotnil_in_objconstr.nim +++ b/tests/notnil/tnotnil_in_objconstr.nim @@ -2,7 +2,7 @@ discard """ errormsg: "fields not initialized: bar" line: "13" """ - +{.experimental: "notnil".} # bug #2355 type Foo = object