diff options
author | Matthew Baulch <baulch.matt@gmail.com> | 2016-07-11 19:12:05 +1000 |
---|---|---|
committer | Matthew Baulch <baulch.matt@gmail.com> | 2016-07-11 19:12:05 +1000 |
commit | d05e146b30aef398164d11e04175c375c74d9463 (patch) | |
tree | 120e60b64b32755478aed9326a415240631d491d | |
parent | d7e172a6bc351ed926f93b77a14fc5cddbce3293 (diff) | |
download | Nim-d05e146b30aef398164d11e04175c375c74d9463.tar.gz |
Recursively check literals for tyEmpty.
-rw-r--r-- | compiler/semstmts.nim | 10 | ||||
-rw-r--r-- | tests/types/tassignemptytuple.nim | 11 |
2 files changed, 19 insertions, 2 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 0fb770875..40462a1da 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -411,6 +411,13 @@ proc semUsing(c: PContext; n: PNode): PNode = if a.sons[length-1].kind != nkEmpty: 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 = var b: PNode result = copyNode(n) @@ -445,8 +452,7 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode = #changeType(def.skipConv, typ, check=true) else: typ = skipIntLit(def.typ) - if typ.kind in {tySequence, tyArray, tySet} and - typ.lastSon.kind == tyEmpty: + if hasEmpty(typ): localError(def.info, errCannotInferTypeOfTheLiteral, ($typ.kind).substr(2).toLower) else: diff --git a/tests/types/tassignemptytuple.nim b/tests/types/tassignemptytuple.nim new file mode 100644 index 000000000..bdfc653a5 --- /dev/null +++ b/tests/types/tassignemptytuple.nim @@ -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) = (@[], (@[], {})) |