'.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
commit 2a278f6eba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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: # old behaviors go here:
defineSymbol(conf.symbols, "nimOldRelativePathBehavior") defineSymbol(conf.symbols, "nimOldRelativePathBehavior")
ast.eqTypeFlags.excl {tfGcSafe, tfNoSideEffect} ast.eqTypeFlags.excl {tfGcSafe, tfNoSideEffect}
conf.globalOptions.incl optNimV1Emulation
else: else:
localError(conf, info, "unknown Nim version; currently supported values are: {1.0}") localError(conf, info, "unknown Nim version; currently supported values are: {1.0}")
of "benchmarkvm": of "benchmarkvm":

View file

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

View file

@ -42,7 +42,7 @@ const
wTags, wLocks, wGcSafe} wTags, wLocks, wGcSafe}
exprPragmas* = {wLine, wLocks, wNoRewrite, wGcSafe, wNoSideEffect} exprPragmas* = {wLine, wLocks, wNoRewrite, wGcSafe, wNoSideEffect}
stmtPragmas* = {wChecks, wObjChecks, wFieldChecks, wRangeChecks, stmtPragmas* = {wChecks, wObjChecks, wFieldChecks, wRangeChecks,
wBoundChecks, wOverflowChecks, wNilChecks, wStaticBoundchecks, wBoundChecks, wOverflowChecks, wNilChecks, wStaticBoundchecks,
wStyleChecks, wAssertions, wStyleChecks, wAssertions,
wWarnings, wHints, wWarnings, wHints,
wLineDir, wStackTrace, wLineTrace, wOptimization, wHint, wWarning, wError, 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 wCodegenDecl: processCodegenDecl(c, it, sym)
of wChecks, wObjChecks, wFieldChecks, wRangeChecks, wBoundChecks, of wChecks, wObjChecks, wFieldChecks, wRangeChecks, wBoundChecks,
wOverflowChecks, wNilChecks, wAssertions, wWarnings, wHints, wOverflowChecks, wNilChecks, wAssertions, wWarnings, wHints,
wLineDir, wOptimization, wStaticBoundchecks, wStyleChecks, wLineDir, wOptimization, wStaticBoundchecks, wStyleChecks,
wCallconv, wDebugger, wProfiler, wCallconv, wDebugger, wProfiler,
wFloatChecks, wNanChecks, wInfChecks, wPatterns, wTrMacros: wFloatChecks, wNanChecks, wInfChecks, wPatterns, wTrMacros:
processOption(c, it, c.config.options) 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 else: sym.flags.incl sfUsed
of wLiftLocals: discard of wLiftLocals: discard
else: invalidPragma(c, it) 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" discard "ignore the .push pragma; it doesn't apply"
else: else:
if sym == nil or (sym.kind in {skVar, skLet, skParam, 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: if n[1].kind != nkEmpty and n[1].len > 0:
pragma(c, s, n[1], procTypePragmas) pragma(c, s, n[1], procTypePragmas)
when useEffectSystem: setEffectsForProcType(c.graph, result, n[1]) 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) closeScope(c)
proc symFromExpectedTypeNode(c: PContext, n: PNode): PSym = proc symFromExpectedTypeNode(c: PContext, n: PNode): PSym =

View file

@ -1,7 +1,13 @@
discard """ 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" 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 type
@ -18,3 +24,16 @@ proc lier(): int {.raises: [IO2Error].} =
proc forw: int = proc forw: int =
raise newException(IOError, "arg") 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.}