* add inUncheckedAssignSection * add one more test
This commit is contained in:
parent
ef3f343ec2
commit
9c17a32e0e
4 changed files with 39 additions and 2 deletions
|
|
@ -2932,7 +2932,21 @@ proc expr(p: BProc, n: PNode, d: var TLoc) =
|
||||||
nkFromStmt, nkTemplateDef, nkMacroDef, nkStaticStmt:
|
nkFromStmt, nkTemplateDef, nkMacroDef, nkStaticStmt:
|
||||||
discard
|
discard
|
||||||
of nkPragma: genPragma(p, n)
|
of nkPragma: genPragma(p, n)
|
||||||
of nkPragmaBlock: expr(p, n.lastSon, d)
|
of nkPragmaBlock:
|
||||||
|
var inUncheckedAssignSection = 0
|
||||||
|
let pragmaList = n[0]
|
||||||
|
for pi in pragmaList:
|
||||||
|
if whichPragma(pi) == wCast:
|
||||||
|
case whichPragma(pi[1])
|
||||||
|
of wUncheckedAssign:
|
||||||
|
inUncheckedAssignSection = 1
|
||||||
|
else:
|
||||||
|
discard
|
||||||
|
|
||||||
|
inc p.inUncheckedAssignSection, inUncheckedAssignSection
|
||||||
|
expr(p, n.lastSon, d)
|
||||||
|
dec p.inUncheckedAssignSection, inUncheckedAssignSection
|
||||||
|
|
||||||
of nkProcDef, nkFuncDef, nkMethodDef, nkConverterDef:
|
of nkProcDef, nkFuncDef, nkMethodDef, nkConverterDef:
|
||||||
if n[genericParamsPos].kind == nkEmpty:
|
if n[genericParamsPos].kind == nkEmpty:
|
||||||
var prc = n[namePos].sym
|
var prc = n[namePos].sym
|
||||||
|
|
|
||||||
|
|
@ -1566,7 +1566,7 @@ proc asgnFieldDiscriminant(p: BProc, e: PNode) =
|
||||||
initLocExpr(p, e[0], a)
|
initLocExpr(p, e[0], a)
|
||||||
getTemp(p, a.t, tmp)
|
getTemp(p, a.t, tmp)
|
||||||
expr(p, e[1], tmp)
|
expr(p, e[1], tmp)
|
||||||
if optTinyRtti notin p.config.globalOptions:
|
if optTinyRtti notin p.config.globalOptions and p.inUncheckedAssignSection == 0:
|
||||||
let field = dotExpr[1].sym
|
let field = dotExpr[1].sym
|
||||||
genDiscriminantCheck(p, a, tmp, dotExpr[0].typ, field)
|
genDiscriminantCheck(p, a, tmp, dotExpr[0].typ, field)
|
||||||
message(p.config, e.info, warnCaseTransition)
|
message(p.config, e.info, warnCaseTransition)
|
||||||
|
|
|
||||||
|
|
@ -99,6 +99,7 @@ type
|
||||||
withinTryWithExcept*: int # required for goto based exception handling
|
withinTryWithExcept*: int # required for goto based exception handling
|
||||||
withinBlockLeaveActions*: int # complex to explain
|
withinBlockLeaveActions*: int # complex to explain
|
||||||
sigConflicts*: CountTable[string]
|
sigConflicts*: CountTable[string]
|
||||||
|
inUncheckedAssignSection*: int
|
||||||
|
|
||||||
TTypeSeq* = seq[PType]
|
TTypeSeq* = seq[PType]
|
||||||
TypeCache* = Table[SigHash, Rope]
|
TypeCache* = Table[SigHash, Rope]
|
||||||
|
|
|
||||||
|
|
@ -34,3 +34,25 @@ proc passToVar(x: var Token) = discard
|
||||||
t.curr = TokenObject(kind: t.curr.kind, foo: "abc")
|
t.curr = TokenObject(kind: t.curr.kind, foo: "abc")
|
||||||
|
|
||||||
t.curr.kind = Token.foo
|
t.curr.kind = Token.foo
|
||||||
|
|
||||||
|
|
||||||
|
block:
|
||||||
|
type
|
||||||
|
TokenKind = enum
|
||||||
|
strLit, intLit
|
||||||
|
Token = object
|
||||||
|
case kind*: TokenKind
|
||||||
|
of strLit:
|
||||||
|
s*: string
|
||||||
|
of intLit:
|
||||||
|
i*: int64
|
||||||
|
|
||||||
|
var t = Token(kind: strLit, s: "abc")
|
||||||
|
|
||||||
|
{.cast(uncheckedAssign).}:
|
||||||
|
|
||||||
|
# inside the 'cast' section it is allowed to assign to the 't.kind' field directly:
|
||||||
|
t.kind = intLit
|
||||||
|
|
||||||
|
{.cast(uncheckedAssign).}:
|
||||||
|
t.kind = strLit
|
||||||
Loading…
Add table
Add a link
Reference in a new issue