From ac271e76b18110bea8046af64ceccd6b804978dd Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Sun, 16 Mar 2014 11:39:53 +0200 Subject: [PATCH] more robust handling of proc signatures containing inter-param type references --- compiler/semexprs.nim | 13 ++++--- compiler/seminst.nim | 69 +++++++++++++++++++++++++++++------ compiler/semtypes.nim | 22 +++++++---- compiler/semtypinst.nim | 10 ++--- compiler/sigmatch.nim | 13 ++++++- tests/generics/tsigtypeop.nim | 9 +++++ 6 files changed, 106 insertions(+), 30 deletions(-) create mode 100644 tests/generics/tsigtypeop.nim diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 133b4ac1e2..5a12156ec1 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -899,10 +899,13 @@ proc makeDeref(n: PNode): PNode = addSon(result, a) t = skipTypes(t.sons[0], {tyGenericInst}) -proc readTypeParameter(c: PContext, ty: PType, +const tyTypeParamsHolders = {tyGenericInst, tyCompositeTypeClass} + +proc readTypeParameter(c: PContext, typ: PType, paramName: PIdent, info: TLineInfo): PNode = - internalAssert ty.kind == tyGenericInst - let ty = ty.skipGenericAlias + let ty = if typ.kind == tyGenericInst: typ.skipGenericAlias + else: (internalAssert typ.kind == tyCompositeTypeClass; typ.sons[1]) + let tbody = ty.sons[0] for s in countup(0, tbody.len-2): let tParam = tbody.sons[s] @@ -946,7 +949,7 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode = result.typ = ty markUsed(n, f) return - of tyGenericInst: + of tyTypeParamsHolders: return readTypeParameter(c, ty, i, n.info) of tyObject, tyTuple: if ty.n.kind == nkRecList: @@ -996,7 +999,7 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode = result = n # we didn't find any field, let's look for a generic param - if result == nil and n.sons[0].typ.kind == tyGenericInst: + if result == nil and n.sons[0].typ.kind in tyTypeParamsHolders: result = readTypeParameter(c, n.sons[0].typ, i, n.info) proc dotTransformation(c: PContext, n: PNode): PNode = diff --git a/compiler/seminst.nim b/compiler/seminst.nim index dca9e33787..3d3227e4e8 100644 --- a/compiler/seminst.nim +++ b/compiler/seminst.nim @@ -85,19 +85,21 @@ proc freshGenSyms(n: PNode, owner: PSym, symMap: var TIdTable) = proc addParamOrResult(c: PContext, param: PSym, kind: TSymKind) +proc addProcDecls(c: PContext, fn: PSym) = + # get the proc itself in scope (e.g. for recursion) + addDecl(c, fn) + + for i in 1 ..