From 08afa030756cd3209520f6db596605116bc246ac Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Wed, 1 Apr 2020 04:01:25 +0300 Subject: [PATCH] The raises list can now use expressions referencing the generic params --- compiler/pragmas.nim | 11 +++++++---- compiler/sem.nim | 1 + compiler/semdata.nim | 2 ++ compiler/sempass2.nim | 7 ++++++- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index 100ce15602..6816a1705d 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -637,10 +637,13 @@ proc processPragma(c: PContext, n: PNode, i: int) = proc pragmaRaisesOrTags(c: PContext, n: PNode) = proc processExc(c: PContext, x: PNode) = - var t = skipTypes(c.semTypeNode(c, x, nil), skipPtrs) - if t.kind != tyObject: - localError(c.config, x.info, errGenerated, "invalid type for raises/tags list") - x.typ = t + if c.hasUnresolvedArgs(c, x): + x.typ = makeTypeFromExpr(c, x) + else: + var t = skipTypes(c.semTypeNode(c, x, nil), skipPtrs) + if t.kind != tyObject and not t.isMetaType: + localError(c.config, x.info, errGenerated, "invalid type for raises/tags list") + x.typ = t if n.kind in nkPragmaCallKinds and n.len == 2: let it = n[1] diff --git a/compiler/sem.nim b/compiler/sem.nim index 471a300995..1ced234f57 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -521,6 +521,7 @@ proc myOpen(graph: ModuleGraph; module: PSym): PPassContext = c.semGenerateInstance = generateInstance c.semTypeNode = semTypeNode c.instTypeBoundOp = sigmatch.instTypeBoundOp + c.hasUnresolvedArgs = hasUnresolvedArgs pushProcCon(c, module) pushOwner(c, c.module) diff --git a/compiler/semdata.nim b/compiler/semdata.nim index fbc9762f3b..7ec4c423f9 100644 --- a/compiler/semdata.nim +++ b/compiler/semdata.nim @@ -104,6 +104,8 @@ type semTryExpr*: proc (c: PContext, n: PNode, flags: TExprFlags = {}): PNode {.nimcall.} semTryConstExpr*: proc (c: PContext, n: PNode): PNode {.nimcall.} computeRequiresInit*: proc (c: PContext, t: PType): bool {.nimcall.} + hasUnresolvedArgs*: proc (c: PContext, n: PNode): bool + semOperand*: proc (c: PContext, n: PNode, flags: TExprFlags = {}): PNode {.nimcall.} semConstBoolExpr*: proc (c: PContext, n: PNode): PNode {.nimcall.} # XXX bite the bullet semOverloadedCall*: proc (c: PContext, n, nOrig: PNode, diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim index a4e1dcf007..86149330e5 100644 --- a/compiler/sempass2.nim +++ b/compiler/sempass2.nim @@ -1083,7 +1083,12 @@ proc track(tracked: PEffects, n: PNode) = for i in 0..