From f0953db3ba59f2e23df2fb7932c672f5020db5fb Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Sun, 16 Mar 2014 17:12:30 +0200 Subject: [PATCH] handle arbitrary expressions dependent on static input params in proc signatures --- compiler/ast.nim | 3 ++- compiler/ccgutils.nim | 5 +++-- compiler/semexprs.nim | 14 +++++++++++++- compiler/semtypes.nim | 8 +++++--- compiler/semtypinst.nim | 9 ++++++--- compiler/sigmatch.nim | 8 ++++++-- compiler/types.nim | 11 +++++++---- tests/effects/teffects1.nim | 2 +- tests/generics/tlateboundstatic.nim | 16 ++++++++++++++++ tests/overload/tissue966.nim | 2 +- 10 files changed, 60 insertions(+), 18 deletions(-) create mode 100644 tests/generics/tlateboundstatic.nim diff --git a/compiler/ast.nim b/compiler/ast.nim index a48ba9dc5a..1dff215037 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -432,8 +432,9 @@ type tfFromGeneric, # type is an instantiation of a generic; this is needed # because for instantiations of objects, structural # type equality has to be used - tfUnresolved, # marks unresolved typedesc params: e.g. + tfUnresolved, # marks unresolved typedesc/static params: e.g. # proc foo(T: typedesc, list: seq[T]): var T + # proc foo(L: static[int]): array[L, int] tfRetType, # marks return types in proc (used to detect type classes # used as return types for return type inference) tfCapturesEnv, # whether proc really captures some environment diff --git a/compiler/ccgutils.nim b/compiler/ccgutils.nim index da1673ca40..1d8f0158b0 100644 --- a/compiler/ccgutils.nim +++ b/compiler/ccgutils.nim @@ -87,9 +87,10 @@ proc getUniqueType*(key: PType): PType = gCanonicalTypes[k] = key result = key of tyTypeDesc, tyTypeClasses, tyGenericParam, - tyFromExpr, tyStatic, tyFieldAccessor: + tyFromExpr, tyFieldAccessor: internalError("GetUniqueType") - of tyGenericInst, tyDistinct, tyOrdinal, tyMutable, tyConst, tyIter: + of tyGenericInst, tyDistinct, tyOrdinal, tyMutable, + tyConst, tyIter, tyStatic: result = getUniqueType(lastSon(key)) of tyArrayConstr, tyGenericInvokation, tyGenericBody, tyOpenArray, tyArray, tySet, tyRange, tyTuple, diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 5a12156ec1..2c7408047f 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -612,7 +612,19 @@ proc evalAtCompileTime(c: PContext, n: PNode): PNode = if result.isNil: result = n else: return result result.typ = semfold.getIntervalType(callee.magic, call) - + + block maybeLabelAsStatic: + # XXX: temporary work-around needed for tlateboundstatic. + # This is certainly not correct, but it will get the job + # done until we have a more robust infrastructure for + # implicit statics. + if n.len > 1: + for i in 1 ..