Recursively check literals for tyEmpty.
This commit is contained in:
parent
d7e172a6bc
commit
d05e146b30
2 changed files with 19 additions and 2 deletions
|
|
@ -411,6 +411,13 @@ proc semUsing(c: PContext; n: PNode): PNode =
|
||||||
if a.sons[length-1].kind != nkEmpty:
|
if a.sons[length-1].kind != nkEmpty:
|
||||||
localError(a.info, "'using' sections cannot contain assignments")
|
localError(a.info, "'using' sections cannot contain assignments")
|
||||||
|
|
||||||
|
proc hasEmpty(typ: PType): bool =
|
||||||
|
if typ.kind in {tySequence, tyArray, tySet}:
|
||||||
|
result = typ.lastSon.kind == tyEmpty
|
||||||
|
elif typ.kind == tyTuple:
|
||||||
|
for s in typ.sons:
|
||||||
|
result = result or hasEmpty(s)
|
||||||
|
|
||||||
proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
|
proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
|
||||||
var b: PNode
|
var b: PNode
|
||||||
result = copyNode(n)
|
result = copyNode(n)
|
||||||
|
|
@ -445,8 +452,7 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
|
||||||
#changeType(def.skipConv, typ, check=true)
|
#changeType(def.skipConv, typ, check=true)
|
||||||
else:
|
else:
|
||||||
typ = skipIntLit(def.typ)
|
typ = skipIntLit(def.typ)
|
||||||
if typ.kind in {tySequence, tyArray, tySet} and
|
if hasEmpty(typ):
|
||||||
typ.lastSon.kind == tyEmpty:
|
|
||||||
localError(def.info, errCannotInferTypeOfTheLiteral,
|
localError(def.info, errCannotInferTypeOfTheLiteral,
|
||||||
($typ.kind).substr(2).toLower)
|
($typ.kind).substr(2).toLower)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
11
tests/types/tassignemptytuple.nim
Normal file
11
tests/types/tassignemptytuple.nim
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
discard """
|
||||||
|
file: "tassignemptytuple.nim"
|
||||||
|
line: 11
|
||||||
|
errormsg: "cannot infer the type of the tuple"
|
||||||
|
"""
|
||||||
|
|
||||||
|
var
|
||||||
|
foo: seq[int]
|
||||||
|
bar: tuple[a: seq[int], b: set[char]]
|
||||||
|
|
||||||
|
(foo, bar) = (@[], (@[], {}))
|
||||||
Loading…
Add table
Add a link
Reference in a new issue