mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-15 15:44:14 +00:00
fixes #5354
This commit is contained in:
@@ -1093,11 +1093,11 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||
return readTypeParameter(c, ty, i, n.info)
|
||||
of tyObject, tyTuple:
|
||||
if ty.n != nil and ty.n.kind == nkRecList:
|
||||
for field in ty.n:
|
||||
if field.sym.name == i:
|
||||
n.typ = newTypeWithSons(c, tyFieldAccessor, @[ty, field.sym.typ])
|
||||
n.typ.n = copyTree(n)
|
||||
return n
|
||||
let field = lookupInRecord(ty.n, i)
|
||||
if field != nil:
|
||||
n.typ = newTypeWithSons(c, tyFieldAccessor, @[ty, field.typ])
|
||||
n.typ.n = copyTree(n)
|
||||
return n
|
||||
else:
|
||||
# echo "TYPE FIELD ACCESS"
|
||||
# debug ty
|
||||
|
||||
17
tests/metatype/tfieldaccessor.nim
Normal file
17
tests/metatype/tfieldaccessor.nim
Normal file
@@ -0,0 +1,17 @@
|
||||
type
|
||||
Test = object
|
||||
x: int
|
||||
case p: bool
|
||||
of true:
|
||||
a: int
|
||||
else:
|
||||
case q: bool
|
||||
of true:
|
||||
b: int
|
||||
else:
|
||||
discard
|
||||
|
||||
proc f[T](t: typedesc[T]): int =
|
||||
1
|
||||
|
||||
assert Test.f == 1
|
||||
Reference in New Issue
Block a user