bugfix: 'not nil' and 'shared' types
This commit is contained in:
parent
0916137287
commit
8948a97151
5 changed files with 23 additions and 5 deletions
|
|
@ -787,6 +787,12 @@ proc semTypeExpr(c: PContext, n: PNode): PType =
|
||||||
else:
|
else:
|
||||||
LocalError(n.info, errTypeExpected, n.renderTree)
|
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 =
|
proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||||
result = nil
|
result = nil
|
||||||
if gCmd == cmdIdeTools: suggestExpr(c, n)
|
if gCmd == cmdIdeTools: suggestExpr(c, n)
|
||||||
|
|
@ -825,7 +831,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||||
checkSonsLen(n, 3)
|
checkSonsLen(n, 3)
|
||||||
result = semTypeNode(c, n.sons[1], prev)
|
result = semTypeNode(c, n.sons[1], prev)
|
||||||
if result.kind in NilableTypes and n.sons[2].kind == nkNilLit:
|
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)
|
result.flags.incl(tfNotNil)
|
||||||
else:
|
else:
|
||||||
LocalError(n.info, errGenerated, "invalid type")
|
LocalError(n.info, errGenerated, "invalid type")
|
||||||
|
|
@ -920,6 +926,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||||
of nkSharedTy:
|
of nkSharedTy:
|
||||||
checkSonsLen(n, 1)
|
checkSonsLen(n, 1)
|
||||||
result = semTypeNode(c, n.sons[0], prev)
|
result = semTypeNode(c, n.sons[0], prev)
|
||||||
|
result = freshType(result, prev)
|
||||||
result.flags.incl(tfShared)
|
result.flags.incl(tfShared)
|
||||||
else:
|
else:
|
||||||
LocalError(n.info, errTypeExpected)
|
LocalError(n.info, errTypeExpected)
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@
|
||||||
## For OpenSSL support compile with ``-d:ssl``. When using SSL be aware that
|
## For OpenSSL support compile with ``-d:ssl``. When using SSL be aware that
|
||||||
## most functions will then raise ``ESSL`` on SSL errors.
|
## most functions will then raise ``ESSL`` on SSL errors.
|
||||||
|
|
||||||
|
{.deadCodeElim: on.}
|
||||||
|
|
||||||
when hostos == "solaris":
|
when hostos == "solaris":
|
||||||
{.passl: "-lsocket -lnsl".}
|
{.passl: "-lsocket -lnsl".}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,8 @@
|
||||||
|
|
||||||
## OpenSSL support
|
## OpenSSL support
|
||||||
|
|
||||||
|
{.deadCodeElim: on.}
|
||||||
|
|
||||||
when defined(WINDOWS):
|
when defined(WINDOWS):
|
||||||
const
|
const
|
||||||
DLLSSLName = "(ssleay32|libssl32).dll"
|
DLLSSLName = "(ssleay32|libssl32).dll"
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
line: 11
|
line: 22
|
||||||
errormgs: "type mismatch"
|
errormgs: "type mismatch"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
@ -8,8 +8,16 @@ type
|
||||||
TObj = object
|
TObj = object
|
||||||
x: int
|
x: int
|
||||||
|
|
||||||
var x: PObj = nil
|
MyString = string not nil
|
||||||
|
|
||||||
|
#var x: PObj = nil
|
||||||
|
|
||||||
proc p(x: string not nil): int =
|
proc p(x: string not nil): int =
|
||||||
result = 45
|
result = 45
|
||||||
|
|
||||||
|
proc q(x: MyString) = nil
|
||||||
|
proc q2(x: string) = nil
|
||||||
|
|
||||||
|
q2(nil)
|
||||||
|
q(nil)
|
||||||
|
|
||||||
|
|
|
||||||
3
todo.txt
3
todo.txt
|
|
@ -1,7 +1,6 @@
|
||||||
version 0.9.2
|
version 0.9.2
|
||||||
=============
|
=============
|
||||||
|
|
||||||
- fix tfShared and tfNotNil
|
|
||||||
- test&finish first class iterators:
|
- test&finish first class iterators:
|
||||||
* nested iterators
|
* nested iterators
|
||||||
* test generic iterators
|
* test generic iterators
|
||||||
|
|
@ -20,7 +19,7 @@ version 0.9.X
|
||||||
=============
|
=============
|
||||||
|
|
||||||
- implement the missing features wrt inheritance
|
- implement the missing features wrt inheritance
|
||||||
- implement generic methods
|
- implement generic methods and generic converters
|
||||||
- improve the compiler as a service
|
- improve the compiler as a service
|
||||||
- ``=`` should be overloadable; requires specialization for ``=``
|
- ``=`` should be overloadable; requires specialization for ``=``
|
||||||
- implement constructors + full 'not nil' checking
|
- implement constructors + full 'not nil' checking
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue