make 'not nil' experimental
This commit is contained in:
parent
cc0ca43743
commit
599b5d6dcb
14 changed files with 27 additions and 16 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
## v0.X.X - XX/XX/2018
|
## v0.19.X - XX/XX/2018
|
||||||
|
|
||||||
### Changes affecting backwards compatibility
|
### Changes affecting backwards compatibility
|
||||||
|
|
||||||
|
|
@ -14,6 +14,9 @@
|
||||||
- Assignments that would "slice" an object into its supertype are now prevented
|
- Assignments that would "slice" an object into its supertype are now prevented
|
||||||
at runtime. Use ``ref object`` with inheritance rather than ``object`` with
|
at runtime. Use ``ref object`` with inheritance rather than ``object`` with
|
||||||
inheritance to prevent this issue.
|
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
|
#### Breaking changes in the standard library
|
||||||
|
|
|
||||||
|
|
@ -116,3 +116,4 @@ proc initDefines*() =
|
||||||
defineSymbol("nimVmEqIdent")
|
defineSymbol("nimVmEqIdent")
|
||||||
defineSymbol("nimNoNil")
|
defineSymbol("nimNoNil")
|
||||||
defineSymbol("nimNoZeroTerminator")
|
defineSymbol("nimNoZeroTerminator")
|
||||||
|
defineSymbol("nimNotNil")
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,8 @@ type
|
||||||
dotOperators,
|
dotOperators,
|
||||||
callOperator,
|
callOperator,
|
||||||
parallel,
|
parallel,
|
||||||
destructor
|
destructor,
|
||||||
|
notnil
|
||||||
|
|
||||||
ConfigRef* = ref object ## eventually all global configuration should be moved here
|
ConfigRef* = ref object ## eventually all global configuration should be moved here
|
||||||
cppDefines*: HashSet[string]
|
cppDefines*: HashSet[string]
|
||||||
|
|
|
||||||
|
|
@ -1389,6 +1389,8 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||||
n.sons[2].kind == nkNilLit:
|
n.sons[2].kind == nkNilLit:
|
||||||
result = freshType(result, prev)
|
result = freshType(result, prev)
|
||||||
result.flags.incl(tfNotNil)
|
result.flags.incl(tfNotNil)
|
||||||
|
if notnil notin c.features:
|
||||||
|
localError(n.info, "enable the 'not nil' annotation with {.experimental: \"notnil\".}")
|
||||||
else:
|
else:
|
||||||
localError(n.info, errGenerated, "invalid type")
|
localError(n.info, errGenerated, "invalid type")
|
||||||
of 2:
|
of 2:
|
||||||
|
|
|
||||||
|
|
@ -3223,7 +3223,7 @@ when not defined(JS): #and not defined(nimscript):
|
||||||
when declared(initGC): initGC()
|
when declared(initGC): initGC()
|
||||||
|
|
||||||
when not defined(nimscript):
|
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
|
## allows you to override the behaviour of your application when CTRL+C
|
||||||
## is pressed. Only one such hook is supported.
|
## is pressed. Only one such hook is supported.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -503,7 +503,7 @@ when not defined(noSignalHandler) and not defined(useNimRtl):
|
||||||
|
|
||||||
registerSignalHandler() # call it in initialization section
|
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:
|
# ugly cast, but should work on all architectures:
|
||||||
type SignalHandler = proc (sign: cint) {.noconv, benign.}
|
type SignalHandler = proc (sign: cint) {.noconv, benign.}
|
||||||
c_signal(SIGINT, cast[SignalHandler](hook))
|
c_signal(SIGINT, cast[SignalHandler](hook))
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ discard """
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# bug #6682
|
# bug #6682
|
||||||
|
{.experimental: "notnil".}
|
||||||
|
|
||||||
type
|
type
|
||||||
Fields = enum
|
Fields = enum
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ discard """
|
||||||
line: 22
|
line: 22
|
||||||
errormsg: "type mismatch"
|
errormsg: "type mismatch"
|
||||||
"""
|
"""
|
||||||
|
{.experimental: "notnil".}
|
||||||
type
|
type
|
||||||
PObj = ref TObj not nil
|
PObj = ref TObj not nil
|
||||||
TObj = object
|
TObj = object
|
||||||
|
|
@ -15,8 +15,8 @@ type
|
||||||
proc p(x: string not nil): int =
|
proc p(x: string not nil): int =
|
||||||
result = 45
|
result = 45
|
||||||
|
|
||||||
proc q(x: MyString) = nil
|
proc q(x: MyString) = discard
|
||||||
proc q2(x: string) = nil
|
proc q2(x: string) = discard
|
||||||
|
|
||||||
q2(nil)
|
q2(nil)
|
||||||
q(nil)
|
q(nil)
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ discard """
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import strutils
|
import strutils
|
||||||
|
{.experimental: "notnil".}
|
||||||
|
|
||||||
type
|
type
|
||||||
TObj = object
|
TObj = object
|
||||||
|
|
@ -18,13 +18,13 @@ proc q(s: superstring) =
|
||||||
echo s
|
echo s
|
||||||
|
|
||||||
proc p2() =
|
proc p2() =
|
||||||
var a: string = "I am not nil"
|
var a: string = "I am not nil"
|
||||||
q(a) # but this should and does not
|
q(a) # but this should and does not
|
||||||
|
|
||||||
p2()
|
p2()
|
||||||
|
|
||||||
proc q(x: pointer not nil) =
|
proc q(x: pointer not nil) =
|
||||||
nil
|
discard
|
||||||
|
|
||||||
proc p() =
|
proc p() =
|
||||||
var x: pointer
|
var x: pointer
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ discard """
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import strutils
|
import strutils
|
||||||
|
{.experimental: "notnil".}
|
||||||
|
|
||||||
type
|
type
|
||||||
TObj = object
|
TObj = object
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ discard """
|
||||||
|
|
||||||
# bug #584
|
# bug #584
|
||||||
# Testprogram for 'not nil' check
|
# Testprogram for 'not nil' check
|
||||||
|
{.experimental: "notnil".}
|
||||||
const testWithResult = true
|
const testWithResult = true
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ discard ""
|
||||||
type
|
type
|
||||||
TObj = ref object
|
TObj = ref object
|
||||||
|
|
||||||
|
{.experimental: "notnil".}
|
||||||
|
|
||||||
proc check(a: TObj not nil) =
|
proc check(a: TObj not nil) =
|
||||||
echo repr(a)
|
echo repr(a)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ discard """
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# bug #2216
|
# bug #2216
|
||||||
|
{.experimental: "notnil".}
|
||||||
|
|
||||||
type
|
type
|
||||||
A[T] = ref object
|
A[T] = ref object
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ discard """
|
||||||
errormsg: "fields not initialized: bar"
|
errormsg: "fields not initialized: bar"
|
||||||
line: "13"
|
line: "13"
|
||||||
"""
|
"""
|
||||||
|
{.experimental: "notnil".}
|
||||||
# bug #2355
|
# bug #2355
|
||||||
type
|
type
|
||||||
Foo = object
|
Foo = object
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue