Files
Nim/tests/effects/teffects1.nim
Andreas Rumpf 2a278f6eba '.push raises: []' now also affects proc types (#13776)
* '.push raises: []' now also affects proc types

* fixes the regression

* less disruptive bugfix

* another attempt
2020-03-29 22:00:18 +02:00

40 lines
1.2 KiB
Nim

discard """
errormsg: "type mismatch: got <proc (x: int): string{.noSideEffect, gcsafe, locks: 0.}> but expected 'MyProcType = proc (x: int): string{.closure.}'"
file: "teffects1.nim"
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
TObj {.pure, inheritable.} = object
TObjB = object of TObj
a, b, c: string
IO2Error = ref object of IOError
proc forw: int {. .}
proc lier(): int {.raises: [IO2Error].} =
writeLine stdout, "arg"
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.}