The raises list can now use expressions referencing the generic params

This commit is contained in:
Zahary Karadjov
2020-04-01 04:01:25 +03:00
committed by Andreas Rumpf
parent be95f8fdfa
commit 08afa03075
4 changed files with 16 additions and 5 deletions

View File

@@ -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]

View File

@@ -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)

View File

@@ -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,

View File

@@ -1083,7 +1083,12 @@ proc track(tracked: PEffects, n: PNode) =
for i in 0..<n.safeLen: track(tracked, n[i])
proc subtypeRelation(g: ModuleGraph; spec, real: PNode): bool =
result = safeInheritanceDiff(g.excType(real), spec.typ) <= 0
if spec.typ.kind == tyOr:
for t in spec.typ.sons:
if safeInheritanceDiff(g.excType(real), t) <= 0:
return true
else:
return safeInheritanceDiff(g.excType(real), spec.typ) <= 0
proc checkRaisesSpec(g: ModuleGraph; spec, real: PNode, msg: string, hints: bool;
effectPredicate: proc (g: ModuleGraph; a, b: PNode): bool {.nimcall.}) =