'.push raises: []' now also affects proc types (#13776)

* '.push raises: []' now also affects proc types

* fixes the regression

* less disruptive bugfix

* another attempt
This commit is contained in:
Andreas Rumpf
2020-03-29 22:00:18 +02:00
committed by GitHub
parent 06f8c5cb6f
commit 2a278f6eba
5 changed files with 32 additions and 5 deletions

View File

@@ -877,6 +877,7 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
# old behaviors go here:
defineSymbol(conf.symbols, "nimOldRelativePathBehavior")
ast.eqTypeFlags.excl {tfGcSafe, tfNoSideEffect}
conf.globalOptions.incl optNimV1Emulation
else:
localError(conf, info, "unknown Nim version; currently supported values are: {1.0}")
of "benchmarkvm":

View File

@@ -91,6 +91,7 @@ type # please make sure we have under 32 options
optBenchmarkVM # Enables cpuTime() in the VM
optProduceAsm # produce assembler code
optPanics # turn panics (sysFatal) into a process termination
optNimV1Emulation # emulate Nim v1.0
TGlobalOptions* = set[TGlobalOption]

View File

@@ -42,7 +42,7 @@ const
wTags, wLocks, wGcSafe}
exprPragmas* = {wLine, wLocks, wNoRewrite, wGcSafe, wNoSideEffect}
stmtPragmas* = {wChecks, wObjChecks, wFieldChecks, wRangeChecks,
wBoundChecks, wOverflowChecks, wNilChecks, wStaticBoundchecks,
wBoundChecks, wOverflowChecks, wNilChecks, wStaticBoundchecks,
wStyleChecks, wAssertions,
wWarnings, wHints,
wLineDir, wStackTrace, wLineTrace, wOptimization, wHint, wWarning, wError,
@@ -1029,7 +1029,7 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int,
of wCodegenDecl: processCodegenDecl(c, it, sym)
of wChecks, wObjChecks, wFieldChecks, wRangeChecks, wBoundChecks,
wOverflowChecks, wNilChecks, wAssertions, wWarnings, wHints,
wLineDir, wOptimization, wStaticBoundchecks, wStyleChecks,
wLineDir, wOptimization, wStaticBoundchecks, wStyleChecks,
wCallconv, wDebugger, wProfiler,
wFloatChecks, wNanChecks, wInfChecks, wPatterns, wTrMacros:
processOption(c, it, c.config.options)
@@ -1147,7 +1147,7 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int,
else: sym.flags.incl sfUsed
of wLiftLocals: discard
else: invalidPragma(c, it)
elif comesFromPush and whichKeyword(ident) in {wTags, wRaises}:
elif comesFromPush and whichKeyword(ident) != wInvalid:
discard "ignore the .push pragma; it doesn't apply"
else:
if sym == nil or (sym.kind in {skVar, skLet, skParam,

View File

@@ -1580,6 +1580,12 @@ proc semProcTypeWithScope(c: PContext, n: PNode,
if n[1].kind != nkEmpty and n[1].len > 0:
pragma(c, s, n[1], procTypePragmas)
when useEffectSystem: setEffectsForProcType(c.graph, result, n[1])
elif c.optionStack.len > 0 and optNimV1Emulation notin c.config.globalOptions:
# we construct a fake 'nkProcDef' for the 'mergePragmas' inside 'implicitPragmas'...
s.ast = newTree(nkProcDef, newNodeI(nkEmpty, n.info), newNodeI(nkEmpty, n.info),
newNodeI(nkEmpty, n.info), newNodeI(nkEmpty, n.info), newNodeI(nkEmpty, n.info))
implicitPragmas(c, s, n, {wTags, wRaises})
when useEffectSystem: setEffectsForProcType(c.graph, result, s.ast[pragmasPos])
closeScope(c)
proc symFromExpectedTypeNode(c: PContext, n: PNode): PSym =

View File

@@ -1,7 +1,13 @@
discard """
errormsg: "can raise an unlisted exception: ref IOError"
errormsg: "type mismatch: got <proc (x: int): string{.noSideEffect, gcsafe, locks: 0.}> but expected 'MyProcType = proc (x: int): string{.closure.}'"
file: "teffects1.nim"
line: 17
line: 38
cmd: "nim check $file"
nimout: '''teffects1.nim(22, 28) template/generic instantiation from here
teffects1.nim(23, 13) Error: can raise an unlisted exception: ref IOError
teffects1.nim(22, 29) Hint: 'IO2Error' is declared but not used [XDeclaredButNotUsed]
teffects1.nim(38, 21) Error: type mismatch: got <proc (x: int): string{.noSideEffect, gcsafe, locks: 0.}> but expected 'MyProcType = proc (x: int): string{.closure.}'
.raise effects differ'''
"""
type
@@ -18,3 +24,16 @@ proc lier(): int {.raises: [IO2Error].} =
proc forw: int =
raise newException(IOError, "arg")
{.push raises: [Defect].}
type
MyProcType* = proc(x: int): string #{.raises: [ValueError, Defect].}
proc foo(x: int): string {.raises: [ValueError].} =
if x > 9:
raise newException(ValueError, "Use single digit")
$x
var p: MyProcType = foo
{.pop.}