make 'not nil' experimental

This commit is contained in:
Andreas Rumpf
2018-05-01 10:48:46 +02:00
committed by Araq
parent cc0ca43743
commit 599b5d6dcb
14 changed files with 27 additions and 16 deletions

View File

@@ -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

View File

@@ -116,3 +116,4 @@ proc initDefines*() =
defineSymbol("nimVmEqIdent")
defineSymbol("nimNoNil")
defineSymbol("nimNoZeroTerminator")
defineSymbol("nimNotNil")

View File

@@ -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]

View File

@@ -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:

View File

@@ -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.

View File

@@ -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))

View File

@@ -3,6 +3,7 @@ discard """
"""
# bug #6682
{.experimental: "notnil".}
type
Fields = enum

View File

@@ -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)

View File

@@ -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

View File

@@ -4,7 +4,7 @@ discard """
"""
import strutils
{.experimental: "notnil".}
type
TObj = object

View File

@@ -5,7 +5,7 @@ discard """
# bug #584
# Testprogram for 'not nil' check
{.experimental: "notnil".}
const testWithResult = true
type

View File

@@ -2,6 +2,8 @@ discard ""
type
TObj = ref object
{.experimental: "notnil".}
proc check(a: TObj not nil) =
echo repr(a)

View File

@@ -3,6 +3,7 @@ discard """
"""
# bug #2216
{.experimental: "notnil".}
type
A[T] = ref object

View File

@@ -2,7 +2,7 @@ discard """
errormsg: "fields not initialized: bar"
line: "13"
"""
{.experimental: "notnil".}
# bug #2355
type
Foo = object