parent
7fcf51248b
commit
9c0e5c4c07
2 changed files with 25 additions and 4 deletions
|
|
@ -440,11 +440,11 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
|
||||||
if a.kind notin {nkIdentDefs, nkVarTuple, nkConstDef}: illFormedAst(a, c.config)
|
if a.kind notin {nkIdentDefs, nkVarTuple, nkConstDef}: illFormedAst(a, c.config)
|
||||||
checkMinSonsLen(a, 3, c.config)
|
checkMinSonsLen(a, 3, c.config)
|
||||||
var length = sonsLen(a)
|
var length = sonsLen(a)
|
||||||
var typ: PType
|
|
||||||
|
var typ: PType = nil
|
||||||
if a.sons[length-2].kind != nkEmpty:
|
if a.sons[length-2].kind != nkEmpty:
|
||||||
typ = semTypeNode(c, a.sons[length-2], nil)
|
typ = semTypeNode(c, a.sons[length-2], nil)
|
||||||
else:
|
|
||||||
typ = nil
|
|
||||||
var def: PNode = c.graph.emptyNode
|
var def: PNode = c.graph.emptyNode
|
||||||
if a.sons[length-1].kind != nkEmpty:
|
if a.sons[length-1].kind != nkEmpty:
|
||||||
def = semExprWithType(c, a.sons[length-1], {efAllowDestructor})
|
def = semExprWithType(c, a.sons[length-1], {efAllowDestructor})
|
||||||
|
|
@ -582,9 +582,19 @@ proc semConst(c: PContext, n: PNode): PNode =
|
||||||
if def == nil:
|
if def == nil:
|
||||||
localError(c.config, a.sons[length-1].info, errConstExprExpected)
|
localError(c.config, a.sons[length-1].info, errConstExprExpected)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if def.typ.kind == tyTypeDesc and c.p.owner.kind != skMacro:
|
||||||
|
# prevent the all too common 'const x = int' bug:
|
||||||
|
localError(c.config, def.info, "'typedesc' metatype is not valid here; typed '=' instead of ':'?")
|
||||||
|
def.typ = errorType(c)
|
||||||
|
|
||||||
# check type compatibility between def.typ and typ:
|
# check type compatibility between def.typ and typ:
|
||||||
if typ != nil:
|
if typ != nil:
|
||||||
def = fitRemoveHiddenConv(c, typ, def)
|
if typ.isMetaType:
|
||||||
|
def = inferWithMetatype(c, typ, def)
|
||||||
|
typ = def.typ
|
||||||
|
else:
|
||||||
|
def = fitRemoveHiddenConv(c, typ, def)
|
||||||
else:
|
else:
|
||||||
typ = def.typ
|
typ = def.typ
|
||||||
if typ == nil:
|
if typ == nil:
|
||||||
|
|
|
||||||
|
|
@ -149,3 +149,14 @@ static:
|
||||||
|
|
||||||
static:
|
static:
|
||||||
doAssert foo().i == 1
|
doAssert foo().i == 1
|
||||||
|
|
||||||
|
# #10333
|
||||||
|
block:
|
||||||
|
const
|
||||||
|
encoding: auto = [
|
||||||
|
["", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"],
|
||||||
|
["", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"],
|
||||||
|
["", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"],
|
||||||
|
["", "M", "MM", "MMM", "--", "-", "--", "---", "----", "--"],
|
||||||
|
]
|
||||||
|
doAssert encoding.len == 4
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue