Skip to content

Commit b3f21db

Browse files
authored
fixes #1201; Initializing a variable with no return type proc doesn't cause compile error (#1211)
fixes #1201 Locals with no explicit types may get the type of the value, even if it is a void type. It should reject void types
1 parent 002b1ba commit b3f21db

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

src/nimony/semdecls.nim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ proc semLocal(c: var SemContext; n: var Cursor; kind: SymKind) =
8787
if n.kind == DotToken:
8888
# no explicit type given:
8989
inc n # 3
90+
let orig = n
9091
var it = Item(n: n, typ: c.types.autoType)
9192
if kind == ConstY:
9293
withNewScope c:
@@ -95,6 +96,8 @@ proc semLocal(c: var SemContext; n: var Cursor; kind: SymKind) =
9596
semLocalValue c, it, crucial # 4
9697
n = it.n
9798
let typ = skipModifier(it.typ)
99+
if classifyType(c, typ) == VoidT:
100+
c.buildErr n.info, "expression '" & asNimCode(orig) & "' has no type (or is ambiguous)"
98101
insertType c, typ, beforeType
99102
else:
100103
let typ = semLocalType(c, n) # 3
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tests/nimony/errmsgs/tlocalvoid.nim(5, 5) Error: expression 'foo()' has no type (or is ambiguous)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import std / [assertions]
2+
3+
proc foo = discard
4+
5+
var x = foo()

0 commit comments

Comments
 (0)