@@ -884,6 +884,9 @@ const
884884
885885proc readTypeParameter (c: PContext , typ: PType ,
886886 paramName: PIdent , info: TLineInfo ): PNode =
887+ # Note: This function will return emptyNode when attempting to read
888+ # a static type parameter that is not yet resolved (e.g. this may
889+ # happen in proc signatures such as `proc(x: T): array[T.sizeParam, U]`
887890 if typ.kind in {tyUserTypeClass, tyUserTypeClassInst}:
888891 for statement in typ.n:
889892 case statement.kind
@@ -914,7 +917,10 @@ proc readTypeParameter(c: PContext, typ: PType,
914917 if tParam.sym.name.id == paramName.id:
915918 let rawTyp = ty.sons[s + 1 ]
916919 if rawTyp.kind == tyStatic:
917- return rawTyp.n
920+ if rawTyp.n != nil :
921+ return rawTyp.n
922+ else :
923+ return emptyNode
918924 else :
919925 let foundTyp = makeTypeDesc (c, rawTyp)
920926 return newSymNode (copySym (tParam.sym).linkTo (foundTyp), info)
@@ -1079,21 +1085,43 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
10791085 template tryReadingGenericParam (t: PType ) =
10801086 case t.kind
10811087 of tyTypeParamsHolders:
1082- return readTypeParameter (c, t, i, n.info)
1088+ result = readTypeParameter (c, t, i, n.info)
1089+ if result == emptyNode:
1090+ result = n
1091+ n.typ = makeTypeFromExpr (c, n.copyTree)
1092+ return
10831093 of tyUserTypeClasses:
10841094 if t.isResolvedUserTypeClass:
10851095 return readTypeParameter (c, t, i, n.info)
10861096 else :
10871097 n.typ = makeTypeFromExpr (c, copyTree (n))
10881098 return n
1089- of tyGenericParam:
1099+ of tyGenericParam, tyAnything :
10901100 n.typ = makeTypeFromExpr (c, copyTree (n))
10911101 return n
10921102 else :
10931103 discard
10941104
1095- if isTypeExpr (n.sons[0 ]) or (ty.kind == tyTypeDesc and ty.base.kind != tyNone):
1096- if ty.kind == tyTypeDesc: ty = ty.base
1105+ var argIsType = false
1106+
1107+ if ty.kind == tyTypeDesc:
1108+ if ty.base.kind == tyNone:
1109+ # This is a still unresolved typedesc parameter.
1110+ # If this is a regular proc, then all bets are off and we must return
1111+ # tyFromExpr, but when this happen in a macro this is not a built-in
1112+ # field access and we leave the compiler to compile a normal call:
1113+ if getCurrOwner (c).kind != skMacro:
1114+ n.typ = makeTypeFromExpr (c, n.copyTree)
1115+ return n
1116+ else :
1117+ return nil
1118+ else :
1119+ ty = ty.base
1120+ argIsType = true
1121+ else :
1122+ argIsType = isTypeExpr (n.sons[0 ])
1123+
1124+ if argIsType:
10971125 ty = ty.skipTypes (tyDotOpTransparent)
10981126 case ty.kind
10991127 of tyEnum:
@@ -2186,7 +2214,7 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
21862214 # because of the changed symbol binding, this does not mean that we
21872215 # don't have to check the symbol for semantics here again!
21882216 result = semSym (c, n, n.sym, flags)
2189- of nkEmpty, nkNone, nkCommentStmt:
2217+ of nkEmpty, nkNone, nkCommentStmt, nkType :
21902218 discard
21912219 of nkNilLit:
21922220 if result .typ == nil : result .typ = getSysType (tyNil)
0 commit comments