Skip to content

Commit 7b9e460

Browse files
authored
fixes discard no return type proc (#1206)
ref #1201 We need to inspect the type of its parameter instead of the type of `discard`
1 parent eeeb970 commit 7b9e460

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

src/nimony/renderer.nim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,9 @@ proc gtype(g: var SrcGen, n: var Cursor, c: Context) =
981981
gsub(g, n, c)
982982
else:
983983
skip n
984+
of DotToken:
985+
put(g, tkSymbol, "void")
986+
inc n
984987
else:
985988
gsub(g, n, c)
986989

src/nimony/sem.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1930,8 +1930,8 @@ proc semDiscard(c: var SemContext; it: var Item) =
19301930
var a = Item(n: it.n, typ: c.types.autoType)
19311931
semExpr c, a
19321932
it.n = a.n
1933-
if classifyType(c, it.typ) == VoidT:
1934-
buildErr c, exInfo, "expression of type `" & typeToString(it.typ) & "` must not be discarded"
1933+
if classifyType(c, a.typ) == VoidT:
1934+
buildErr c, exInfo, "expression of type `" & typeToString(a.typ) & "` must not be discarded"
19351935
takeParRi c, it.n
19361936
producesVoid c, info, it.typ
19371937

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tests/nimony/sysbasics/tdiscardvoidcalls.nim(4, 12) Error: expression of type `void` must not be discarded
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
proc foo =
2+
discard
3+
4+
discard foo()

0 commit comments

Comments
 (0)