diff options
author | Araq <rumpf_a@web.de> | 2012-12-02 20:02:42 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-12-02 20:02:42 +0100 |
commit | 8948a97151fc000414aee7cd4064881ef646a26c (patch) | |
tree | 89b5deb1448d0281028f3a02ca28ee11dec09f25 | |
parent | 0916137287b1d1468810f0ad4cf638eed5436f5e (diff) | |
download | Nim-8948a97151fc000414aee7cd4064881ef646a26c.tar.gz |
bugfix: 'not nil' and 'shared' types
-rwxr-xr-x | compiler/semtypes.nim | 9 | ||||
-rwxr-xr-x | lib/pure/sockets.nim | 2 | ||||
-rwxr-xr-x | lib/wrappers/openssl.nim | 2 | ||||
-rw-r--r-- | tests/reject/tnotnil.nim | 12 | ||||
-rwxr-xr-x | todo.txt | 3 |
5 files changed, 23 insertions, 5 deletions
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 9efeba5b7..6478c1ec6 100755 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -787,6 +787,12 @@ proc semTypeExpr(c: PContext, n: PNode): PType = else: LocalError(n.info, errTypeExpected, n.renderTree) +proc freshType(res, prev: PType): PType {.inline.} = + if prev.isNil: + result = copyType(result, result.owner, keepId=false) + else: + result = res + proc semTypeNode(c: PContext, n: PNode, prev: PType): PType = result = nil if gCmd == cmdIdeTools: suggestExpr(c, n) @@ -825,7 +831,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType = checkSonsLen(n, 3) result = semTypeNode(c, n.sons[1], prev) if result.kind in NilableTypes and n.sons[2].kind == nkNilLit: - # XXX this is wrong for tyString at least + result = freshType(result, prev) result.flags.incl(tfNotNil) else: LocalError(n.info, errGenerated, "invalid type") @@ -920,6 +926,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType = of nkSharedTy: checkSonsLen(n, 1) result = semTypeNode(c, n.sons[0], prev) + result = freshType(result, prev) result.flags.incl(tfShared) else: LocalError(n.info, errTypeExpected) diff --git a/lib/pure/sockets.nim b/lib/pure/sockets.nim index 371641b06..6a3c644bd 100755 --- a/lib/pure/sockets.nim +++ b/lib/pure/sockets.nim @@ -14,6 +14,8 @@ ## For OpenSSL support compile with ``-d:ssl``. When using SSL be aware that ## most functions will then raise ``ESSL`` on SSL errors. +{.deadCodeElim: on.} + when hostos == "solaris": {.passl: "-lsocket -lnsl".} diff --git a/lib/wrappers/openssl.nim b/lib/wrappers/openssl.nim index 1063f401d..752e594d1 100755 --- a/lib/wrappers/openssl.nim +++ b/lib/wrappers/openssl.nim @@ -39,6 +39,8 @@ ## OpenSSL support +{.deadCodeElim: on.} + when defined(WINDOWS): const DLLSSLName = "(ssleay32|libssl32).dll" diff --git a/tests/reject/tnotnil.nim b/tests/reject/tnotnil.nim index 8676aedf8..b02e33713 100644 --- a/tests/reject/tnotnil.nim +++ b/tests/reject/tnotnil.nim @@ -1,5 +1,5 @@ discard """ - line: 11 + line: 22 errormgs: "type mismatch" """ @@ -7,9 +7,17 @@ type PObj = ref TObj not nil TObj = object x: int + + MyString = string not nil -var x: PObj = nil +#var x: PObj = nil proc p(x: string not nil): int = result = 45 +proc q(x: MyString) = nil +proc q2(x: string) = nil + +q2(nil) +q(nil) + diff --git a/todo.txt b/todo.txt index ca2def6aa..f736ce8dd 100755 --- a/todo.txt +++ b/todo.txt @@ -1,7 +1,6 @@ version 0.9.2 ============= -- fix tfShared and tfNotNil - test&finish first class iterators: * nested iterators * test generic iterators @@ -20,7 +19,7 @@ version 0.9.X ============= - implement the missing features wrt inheritance -- implement generic methods +- implement generic methods and generic converters - improve the compiler as a service - ``=`` should be overloadable; requires specialization for ``=`` - implement constructors + full 'not nil' checking |