diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2018-05-01 10:48:46 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2018-05-02 13:34:53 +0200 |
commit | 599b5d6dcbd8b73d98d1aaf2de94d3360229a699 (patch) | |
tree | 16dd2abe40bb595864a330dad860b91c6b26da6d | |
parent | cc0ca43743f286d93c0e4b7adddecd7bb3e83e46 (diff) | |
download | Nim-599b5d6dcbd8b73d98d1aaf2de94d3360229a699.tar.gz |
make 'not nil' experimental
-rw-r--r-- | changelog.md | 5 | ||||
-rw-r--r-- | compiler/condsyms.nim | 1 | ||||
-rw-r--r-- | compiler/options.nim | 3 | ||||
-rw-r--r-- | compiler/semtypes.nim | 2 | ||||
-rw-r--r-- | lib/system.nim | 2 | ||||
-rw-r--r-- | lib/system/excpt.nim | 8 | ||||
-rw-r--r-- | tests/notnil/tmust_compile.nim | 1 | ||||
-rw-r--r-- | tests/notnil/tnotnil.nim | 6 | ||||
-rw-r--r-- | tests/notnil/tnotnil1.nim | 6 | ||||
-rw-r--r-- | tests/notnil/tnotnil2.nim | 2 | ||||
-rw-r--r-- | tests/notnil/tnotnil3.nim | 2 | ||||
-rw-r--r-- | tests/notnil/tnotnil4.nim | 2 | ||||
-rw-r--r-- | tests/notnil/tnotnil_in_generic.nim | 1 | ||||
-rw-r--r-- | tests/notnil/tnotnil_in_objconstr.nim | 2 |
14 files changed, 27 insertions, 16 deletions
diff --git a/changelog.md b/changelog.md index 2e1795bab..6cd0faf52 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 b1d0ccc7a..f8a75e68e 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 9f56d3f18..5baaa1bfd 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 1fc263617..537319d66 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 5c0970f85..0c8659fda 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 afeab2b6c..fb38948f7 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 10da154f0..a32c6c7ec 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 f65634ed6..e392b155c 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 73472752c..7f9d02295 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 bd6b8b675..6ab7bf951 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 b7c7a811d..31a4efef7 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 2fa888357..4fd169827 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 357ab2c7c..89d20f182 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 7dce98c29..d33709906 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 |