Fix #5888
This commit is contained in:
parent
a6006e56a7
commit
21ce7b2af4
6 changed files with 43 additions and 2 deletions
|
|
@ -1129,9 +1129,9 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
# reset to prevent 'nil' bug: see "tests/reject/tenumitems.nim":
|
# reset to prevent 'nil' bug: see "tests/reject/tenumitems.nim":
|
||||||
ty = n.sons[0].typ
|
ty = n.sons[0].typ
|
||||||
return nil
|
return nil
|
||||||
ty = skipTypes(ty, {tyGenericInst, tyVar, tyPtr, tyRef, tyAlias})
|
|
||||||
if ty.kind in tyUserTypeClasses and ty.isResolvedUserTypeClass:
|
if ty.kind in tyUserTypeClasses and ty.isResolvedUserTypeClass:
|
||||||
ty = ty.lastSon
|
ty = ty.lastSon
|
||||||
|
ty = skipTypes(ty, {tyGenericInst, tyVar, tyPtr, tyRef, tyAlias})
|
||||||
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:
|
||||||
|
|
|
||||||
|
|
@ -467,6 +467,8 @@ proc hasEmpty(typ: PType): bool =
|
||||||
|
|
||||||
proc makeDeref(n: PNode): PNode =
|
proc makeDeref(n: PNode): PNode =
|
||||||
var t = skipTypes(n.typ, {tyGenericInst, tyAlias})
|
var t = skipTypes(n.typ, {tyGenericInst, tyAlias})
|
||||||
|
if t.kind in tyUserTypeClasses and t.isResolvedUserTypeClass:
|
||||||
|
t = t.lastSon
|
||||||
result = n
|
result = n
|
||||||
if t.kind == tyVar:
|
if t.kind == tyVar:
|
||||||
result = newNodeIT(nkHiddenDeref, n.info, t.sons[0])
|
result = newNodeIT(nkHiddenDeref, n.info, t.sons[0])
|
||||||
|
|
|
||||||
|
|
@ -1415,7 +1415,10 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||||
result = errorType(c)
|
result = errorType(c)
|
||||||
else:
|
else:
|
||||||
result = typeExpr.typ.base
|
result = typeExpr.typ.base
|
||||||
if result.isMetaType:
|
if result.isMetaType and
|
||||||
|
result.kind != tyUserTypeClass:
|
||||||
|
# the dot expression may refer to a concept type in
|
||||||
|
# a different module. allow a normal alias then.
|
||||||
let preprocessed = semGenericStmt(c, n)
|
let preprocessed = semGenericStmt(c, n)
|
||||||
result = makeTypeFromExpr(c, preprocessed.copyTree)
|
result = makeTypeFromExpr(c, preprocessed.copyTree)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
26
tests/concepts/t5888.nim
Normal file
26
tests/concepts/t5888.nim
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
discard """
|
||||||
|
output: '''
|
||||||
|
true
|
||||||
|
true
|
||||||
|
true
|
||||||
|
f
|
||||||
|
0
|
||||||
|
'''
|
||||||
|
"""
|
||||||
|
|
||||||
|
import t5888lib/ca, t5888lib/opt
|
||||||
|
|
||||||
|
type LocalCA = ca.CA
|
||||||
|
|
||||||
|
proc f(c: CA) =
|
||||||
|
echo "f"
|
||||||
|
echo c.x
|
||||||
|
|
||||||
|
var o = new(Opt)
|
||||||
|
|
||||||
|
echo o is CA
|
||||||
|
echo o is LocalCA
|
||||||
|
echo o is ca.CA
|
||||||
|
|
||||||
|
o.f()
|
||||||
|
|
||||||
4
tests/concepts/t5888lib/ca.nim
Normal file
4
tests/concepts/t5888lib/ca.nim
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
type
|
||||||
|
CA* = concept c
|
||||||
|
c.x is int
|
||||||
|
|
||||||
6
tests/concepts/t5888lib/opt.nim
Normal file
6
tests/concepts/t5888lib/opt.nim
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
import ca
|
||||||
|
|
||||||
|
type
|
||||||
|
Opt* = object
|
||||||
|
x*: int
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue