fix #1015
This commit is contained in:
parent
8ba062d952
commit
09bda74e7d
2 changed files with 32 additions and 3 deletions
|
|
@ -931,7 +931,9 @@ proc makeDeref(n: PNode): PNode =
|
||||||
addSon(result, a)
|
addSon(result, a)
|
||||||
t = skipTypes(t.sons[0], {tyGenericInst})
|
t = skipTypes(t.sons[0], {tyGenericInst})
|
||||||
|
|
||||||
const tyTypeParamsHolders = {tyGenericInst, tyCompositeTypeClass}
|
const
|
||||||
|
tyTypeParamsHolders = {tyGenericInst, tyCompositeTypeClass}
|
||||||
|
tyDotOpTransparent = {tyVar, tyPtr, tyRef}
|
||||||
|
|
||||||
proc readTypeParameter(c: PContext, typ: PType,
|
proc readTypeParameter(c: PContext, typ: PType,
|
||||||
paramName: PIdent, info: TLineInfo): PNode =
|
paramName: PIdent, info: TLineInfo): PNode =
|
||||||
|
|
@ -968,6 +970,7 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
result = nil
|
result = nil
|
||||||
if isTypeExpr(n.sons[0]) or (ty.kind == tyTypeDesc and ty.base.kind != tyNone):
|
if isTypeExpr(n.sons[0]) or (ty.kind == tyTypeDesc and ty.base.kind != tyNone):
|
||||||
if ty.kind == tyTypeDesc: ty = ty.base
|
if ty.kind == tyTypeDesc: ty = ty.base
|
||||||
|
ty = ty.skipTypes(tyDotOpTransparent)
|
||||||
case ty.kind
|
case ty.kind
|
||||||
of tyEnum:
|
of tyEnum:
|
||||||
# look up if the identifier belongs to the enum:
|
# look up if the identifier belongs to the enum:
|
||||||
|
|
@ -1031,8 +1034,10 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
result = n
|
result = n
|
||||||
|
|
||||||
# we didn't find any field, let's look for a generic param
|
# we didn't find any field, let's look for a generic param
|
||||||
if result == nil and n.sons[0].typ.kind in tyTypeParamsHolders:
|
if result == nil:
|
||||||
result = readTypeParameter(c, n.sons[0].typ, i, n.info)
|
let t = n.sons[0].typ.skipTypes(tyDotOpTransparent)
|
||||||
|
if t.kind in tyTypeParamsHolders:
|
||||||
|
result = readTypeParameter(c, t, i, n.info)
|
||||||
|
|
||||||
proc dotTransformation(c: PContext, n: PNode): PNode =
|
proc dotTransformation(c: PContext, n: PNode): PNode =
|
||||||
if isSymChoice(n.sons[1]):
|
if isSymChoice(n.sons[1]):
|
||||||
|
|
|
||||||
24
tests/metatype/tusertypeclasses2.nim
Normal file
24
tests/metatype/tusertypeclasses2.nim
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
type
|
||||||
|
hasFieldX = generic z
|
||||||
|
z.x is int
|
||||||
|
|
||||||
|
obj_x = object
|
||||||
|
x: int
|
||||||
|
|
||||||
|
ref_obj_x = ref object
|
||||||
|
x: int
|
||||||
|
|
||||||
|
ref_to_obj_x = ref obj_x
|
||||||
|
|
||||||
|
p_o_x = ptr obj_x
|
||||||
|
v_o_x = var obj_x
|
||||||
|
|
||||||
|
template check(x) =
|
||||||
|
static: assert(x)
|
||||||
|
|
||||||
|
check obj_x is hasFieldX
|
||||||
|
check ref_obj_x is hasFieldX
|
||||||
|
check ref_to_obj_x is hasFieldX
|
||||||
|
check p_o_x is hasFieldX
|
||||||
|
check v_o_x is hasFieldX
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue