Skip to content

Commit 3a0d09c

Browse files
authored
backport to version 2.0: display raises pragma in proc types (#23026) (#23028)
This affects also nimsuggest hints (e.g. on mouse hover), as well as compiler messages. (cherry picked from commit 618ccb6)
1 parent 3ab6012 commit 3a0d09c

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

compiler/types.nim

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import
1313
intsets, ast, astalgo, trees, msgs, strutils, platform, renderer, options,
14-
lineinfos, int128, modulegraphs, astmsgs
14+
lineinfos, int128, modulegraphs, astmsgs, wordrecg
1515

1616
when defined(nimPreviewSlimSystem):
1717
import std/[assertions, formatfloat]
@@ -758,6 +758,14 @@ proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
758758
result.add(')')
759759
if t.len > 0 and t[0] != nil: result.add(": " & typeToString(t[0]))
760760
var prag = if t.callConv == ccNimCall and tfExplicitCallConv notin t.flags: "" else: $t.callConv
761+
if not isNil(t.owner) and not isNil(t.owner.ast) and (t.owner.ast.len - 1) >= pragmasPos:
762+
let pragmasNode = t.owner.ast[pragmasPos]
763+
let raisesSpec = effectSpec(pragmasNode, wRaises)
764+
if not isNil(raisesSpec):
765+
addSep(prag)
766+
prag.add("raises: ")
767+
prag.add($raisesSpec)
768+
761769
if tfNoSideEffect in t.flags:
762770
addSep(prag)
763771
prag.add("noSideEffect")

tests/effects/teffects1.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ proc foo(x: int): string {.nimcall, raises: [ValueError].} =
3939

4040
var p: MyProcType = foo #[tt.Error
4141
^
42-
type mismatch: got <proc (x: int): string{.nimcall, noSideEffect, gcsafe.}> but expected 'MyProcType = proc (x: int): string{.closure.}'
42+
type mismatch: got <proc (x: int): string{.nimcall, raises: [ValueError], noSideEffect, gcsafe.}> but expected 'MyProcType = proc (x: int): string{.closure.}'
4343
Calling convention mismatch: got '{.nimcall.}', but expected '{.closure.}'.
4444
.raise effects differ
4545
]#

0 commit comments

Comments
 (0)