Skip to content

Commit 35543c4

Browse files
committed
The raises list can now use expressions referencing the generic params
1 parent f3337e5 commit 35543c4

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

compiler/pragmas.nim

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -614,10 +614,13 @@ proc processPragma(c: PContext, n: PNode, i: int) =
614614

615615
proc pragmaRaisesOrTags(c: PContext, n: PNode) =
616616
proc processExc(c: PContext, x: PNode) =
617-
var t = skipTypes(c.semTypeNode(c, x, nil), skipPtrs)
618-
if t.kind != tyObject:
619-
localError(c.config, x.info, errGenerated, "invalid type for raises/tags list")
620-
x.typ = t
617+
if c.hasUnresolvedArgs(c, x):
618+
x.typ = makeTypeFromExpr(c, x)
619+
else:
620+
var t = skipTypes(c.semTypeNode(c, x, nil), skipPtrs)
621+
if t.kind != tyObject and not t.isMetaType:
622+
localError(c.config, x.info, errGenerated, "invalid type for raises/tags list")
623+
x.typ = t
621624

622625
if n.kind in nkPragmaCallKinds and n.len == 2:
623626
let it = n[1]

compiler/sem.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ proc myOpen(graph: ModuleGraph; module: PSym): PPassContext =
521521
c.semGenerateInstance = generateInstance
522522
c.semTypeNode = semTypeNode
523523
c.instTypeBoundOp = sigmatch.instTypeBoundOp
524+
c.hasUnresolvedArgs = hasUnresolvedArgs
524525

525526
pushProcCon(c, module)
526527
pushOwner(c, c.module)

compiler/semdata.nim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ type
104104
semTryExpr*: proc (c: PContext, n: PNode, flags: TExprFlags = {}): PNode {.nimcall.}
105105
semTryConstExpr*: proc (c: PContext, n: PNode): PNode {.nimcall.}
106106
computeRequiresInit*: proc (c: PContext, t: PType): bool {.nimcall.}
107+
hasUnresolvedArgs*: proc (c: PContext, n: PNode): bool
108+
107109
semOperand*: proc (c: PContext, n: PNode, flags: TExprFlags = {}): PNode {.nimcall.}
108110
semConstBoolExpr*: proc (c: PContext, n: PNode): PNode {.nimcall.} # XXX bite the bullet
109111
semOverloadedCall*: proc (c: PContext, n, nOrig: PNode,

compiler/sempass2.nim

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,12 @@ proc track(tracked: PEffects, n: PNode) =
10271027
for i in 0..<n.safeLen: track(tracked, n[i])
10281028

10291029
proc subtypeRelation(g: ModuleGraph; spec, real: PNode): bool =
1030-
result = safeInheritanceDiff(g.excType(real), spec.typ) <= 0
1030+
if spec.typ.kind == tyOr:
1031+
for t in spec.typ.sons:
1032+
if safeInheritanceDiff(g.excType(real), t) <= 0:
1033+
return true
1034+
else:
1035+
return safeInheritanceDiff(g.excType(real), spec.typ) <= 0
10311036

10321037
proc checkRaisesSpec(g: ModuleGraph; spec, real: PNode, msg: string, hints: bool;
10331038
effectPredicate: proc (g: ModuleGraph; a, b: PNode): bool {.nimcall.}) =

0 commit comments

Comments
 (0)