fix #5642
This commit is contained in:
parent
eb635d9ccf
commit
fb3ff64450
4 changed files with 31 additions and 3 deletions
|
|
@ -756,7 +756,7 @@ proc genRecordField(p: BProc, e: PNode, d: var TLoc) =
|
||||||
genRecordFieldAux(p, e, d, a)
|
genRecordFieldAux(p, e, d, a)
|
||||||
var r = rdLoc(a)
|
var r = rdLoc(a)
|
||||||
var f = e.sons[1].sym
|
var f = e.sons[1].sym
|
||||||
let ty = skipTypes(a.t, abstractInst)
|
let ty = skipTypes(a.t, abstractInst + tyUserTypeClasses)
|
||||||
if ty.kind == tyTuple:
|
if ty.kind == tyTuple:
|
||||||
# we found a unique tuple type which lacks field information
|
# we found a unique tuple type which lacks field information
|
||||||
# so we use Field$i
|
# so we use Field$i
|
||||||
|
|
|
||||||
|
|
@ -1155,6 +1155,8 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
ty = n.sons[0].typ
|
ty = n.sons[0].typ
|
||||||
return nil
|
return nil
|
||||||
ty = skipTypes(ty, {tyGenericInst, tyVar, tyPtr, tyRef, tyAlias})
|
ty = skipTypes(ty, {tyGenericInst, tyVar, tyPtr, tyRef, tyAlias})
|
||||||
|
if ty.kind in tyUserTypeClasses and ty.isResolvedUserTypeClass:
|
||||||
|
ty = ty.lastSon
|
||||||
while tfBorrowDot in ty.flags: ty = ty.skipTypes({tyDistinct})
|
while tfBorrowDot in ty.flags: ty = ty.skipTypes({tyDistinct})
|
||||||
var check: PNode = nil
|
var check: PNode = nil
|
||||||
if ty.kind == tyObject:
|
if ty.kind == tyObject:
|
||||||
|
|
|
||||||
|
|
@ -121,12 +121,13 @@ proc semForFields(c: PContext, n: PNode, m: TMagic): PNode =
|
||||||
localError(n.info, errWrongNumberOfVariables)
|
localError(n.info, errWrongNumberOfVariables)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
var tupleTypeA = skipTypes(call.sons[1].typ, abstractVar-{tyTypeDesc})
|
const skippedTypesForFields = abstractVar - {tyTypeDesc} + tyUserTypeClasses
|
||||||
|
var tupleTypeA = skipTypes(call.sons[1].typ, skippedTypesForFields)
|
||||||
if tupleTypeA.kind notin {tyTuple, tyObject}:
|
if tupleTypeA.kind notin {tyTuple, tyObject}:
|
||||||
localError(n.info, errGenerated, "no object or tuple type")
|
localError(n.info, errGenerated, "no object or tuple type")
|
||||||
return result
|
return result
|
||||||
for i in 1..call.len-1:
|
for i in 1..call.len-1:
|
||||||
var tupleTypeB = skipTypes(call.sons[i].typ, abstractVar-{tyTypeDesc})
|
var tupleTypeB = skipTypes(call.sons[i].typ, skippedTypesForFields)
|
||||||
if not sameType(tupleTypeA, tupleTypeB):
|
if not sameType(tupleTypeA, tupleTypeB):
|
||||||
typeMismatch(call.sons[i].info, tupleTypeA, tupleTypeB)
|
typeMismatch(call.sons[i].info, tupleTypeA, tupleTypeB)
|
||||||
|
|
||||||
|
|
|
||||||
25
tests/concepts/t5642.nim
Normal file
25
tests/concepts/t5642.nim
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
discard """
|
||||||
|
output: 9
|
||||||
|
"""
|
||||||
|
|
||||||
|
type DataTable = concept x
|
||||||
|
x is object
|
||||||
|
for f in fields(x):
|
||||||
|
f is seq
|
||||||
|
|
||||||
|
type Students = object
|
||||||
|
id : seq[int]
|
||||||
|
name : seq[string]
|
||||||
|
age: seq[int]
|
||||||
|
|
||||||
|
proc nrow*(dt: DataTable) : Natural =
|
||||||
|
var totalLen = 0
|
||||||
|
for f in fields(dt):
|
||||||
|
totalLen += f.len
|
||||||
|
return totalLen
|
||||||
|
|
||||||
|
let
|
||||||
|
stud = Students (id : @[1,2,3], name : @["Vas", "Pas", "NafNaf"], age : @[10,16,32])
|
||||||
|
|
||||||
|
echo nrow(stud)
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue