From d05e146b30aef398164d11e04175c375c74d9463 Mon Sep 17 00:00:00 2001 From: Matthew Baulch Date: Mon, 11 Jul 2016 19:12:05 +1000 Subject: [PATCH] Recursively check literals for tyEmpty. --- compiler/semstmts.nim | 10 ++++++++-- tests/types/tassignemptytuple.nim | 11 +++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 tests/types/tassignemptytuple.nim diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 0fb7708756..40462a1da3 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 0000000000..bdfc653a5e --- /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) = (@[], (@[], {}))