fixes #4207
This commit is contained in:
parent
660cd7ed70
commit
041054e038
3 changed files with 12 additions and 7 deletions
|
|
@ -12,25 +12,26 @@
|
||||||
|
|
||||||
import ast, astalgo, msgs, types
|
import ast, astalgo, msgs, types
|
||||||
|
|
||||||
proc ithField(n: PNode, field: int): PSym =
|
proc ithField(n: PNode, field: var int): PSym =
|
||||||
result = nil
|
result = nil
|
||||||
case n.kind
|
case n.kind
|
||||||
of nkRecList:
|
of nkRecList:
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
result = ithField(n.sons[i], field-i)
|
result = ithField(n.sons[i], field)
|
||||||
if result != nil: return
|
if result != nil: return
|
||||||
of nkRecCase:
|
of nkRecCase:
|
||||||
if n.sons[0].kind != nkSym: internalError(n.info, "ithField")
|
if n.sons[0].kind != nkSym: internalError(n.info, "ithField")
|
||||||
result = ithField(n.sons[0], field-1)
|
result = ithField(n.sons[0], field)
|
||||||
if result != nil: return
|
if result != nil: return
|
||||||
for i in countup(1, sonsLen(n) - 1):
|
for i in countup(1, sonsLen(n) - 1):
|
||||||
case n.sons[i].kind
|
case n.sons[i].kind
|
||||||
of nkOfBranch, nkElse:
|
of nkOfBranch, nkElse:
|
||||||
result = ithField(lastSon(n.sons[i]), field-1)
|
result = ithField(lastSon(n.sons[i]), field)
|
||||||
if result != nil: return
|
if result != nil: return
|
||||||
else: internalError(n.info, "ithField(record case branch)")
|
else: internalError(n.info, "ithField(record case branch)")
|
||||||
of nkSym:
|
of nkSym:
|
||||||
if field == 0: result = n.sym
|
if field == 0: result = n.sym
|
||||||
|
else: dec(field)
|
||||||
else: discard
|
else: discard
|
||||||
|
|
||||||
proc annotateType*(n: PNode, t: PType) =
|
proc annotateType*(n: PNode, t: PType) =
|
||||||
|
|
@ -39,10 +40,13 @@ proc annotateType*(n: PNode, t: PType) =
|
||||||
# to not to skip tyGenericInst
|
# to not to skip tyGenericInst
|
||||||
case n.kind
|
case n.kind
|
||||||
of nkObjConstr:
|
of nkObjConstr:
|
||||||
|
let x = t.skipTypes(abstractPtrs)
|
||||||
n.typ = t
|
n.typ = t
|
||||||
for i in 1 .. <n.len:
|
for i in 1 .. <n.len:
|
||||||
let field = x.n.ithField(i - 1)
|
var j = i-1
|
||||||
if field.isNil: globalError n.info, "invalid field at index " & $i
|
let field = x.n.ithField(j)
|
||||||
|
if field.isNil:
|
||||||
|
globalError n.info, "invalid field at index " & $i
|
||||||
else:
|
else:
|
||||||
internalAssert(n.sons[i].kind == nkExprColonExpr)
|
internalAssert(n.sons[i].kind == nkExprColonExpr)
|
||||||
annotateType(n.sons[i].sons[1], field.typ)
|
annotateType(n.sons[i].sons[1], field.typ)
|
||||||
|
|
|
||||||
|
|
@ -536,7 +536,7 @@ proc semConst(c: PContext, n: PNode): PNode =
|
||||||
localError(a.sons[2].info, errConstExprExpected)
|
localError(a.sons[2].info, errConstExprExpected)
|
||||||
continue
|
continue
|
||||||
if typeAllowed(typ, skConst) != nil and def.kind != nkNilLit:
|
if typeAllowed(typ, skConst) != nil and def.kind != nkNilLit:
|
||||||
localError(a.info, errXisNoType, typeToString(typ))
|
localError(a.info, "invalid type for const: " & typeToString(typ))
|
||||||
continue
|
continue
|
||||||
v.typ = typ
|
v.typ = typ
|
||||||
v.ast = def # no need to copy
|
v.ast = def # no need to copy
|
||||||
|
|
|
||||||
1
todo.txt
1
todo.txt
|
|
@ -2,6 +2,7 @@
|
||||||
nim c --gc:v2 -r -d:useSysAssert -d:useGcAssert -d:smokeCycles -d:useRealtimeGc tests/gc/gctest
|
nim c --gc:v2 -r -d:useSysAssert -d:useGcAssert -d:smokeCycles -d:useRealtimeGc tests/gc/gctest
|
||||||
|
|
||||||
- document ``this`` pragma
|
- document ``this`` pragma
|
||||||
|
- https://github.com/nim-lang/Nim/issues/3898
|
||||||
|
|
||||||
essential for 1.0
|
essential for 1.0
|
||||||
=================
|
=================
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue