From 45c9975e9c9fe063d68aa5eb6df0457ca9ac7457 Mon Sep 17 00:00:00 2001 From: Araq Date: Wed, 20 Feb 2013 01:00:17 +0100 Subject: [PATCH] better typeToString; fixes #340 --- compiler/semstmts.nim | 3 +++ compiler/types.nim | 28 +++++++++++++--------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 2538636975..63e632eca5 100755 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -336,6 +336,9 @@ proc instFieldLoopBody(c: TFieldInstCtx, n: PNode, forLoop: PNode): PNode = result.add(newSymNode(c.field, n.info)) break else: + if n.kind == nkContinueStmt: + localError(n.info, errGenerated, + "'continue' not supported in a 'fields' loop") result = copyNode(n) newSons(result, sonsLen(n)) for i in countup(0, sonsLen(n)-1): diff --git a/compiler/types.nim b/compiler/types.nim index f3c54e2c58..68a1b80563 100755 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -406,21 +406,16 @@ const "bignum", "const ", "!", "varargs[$1]", "iter[$1]", "Error Type", "TypeClass"] -proc constraintsToStr(t: PType): string = - proc consToStr(t: PType): string = - if t.len > 0: result = t.typeToString - else: result = typeToStr[t.kind].strip +proc consToStr(t: PType): string = + if t.len > 0: result = t.typeToString + else: result = typeToStr[t.kind].strip - # better error messages are nice: - case t.len - of 0: result = "constraint[]" - of 1: result = "constraint[" & consToStr(t.sons[0]) & "]" - else: - let sep = if tfAny in t.flags: " or " else: " and " - result = "" - for i in countup(0, t.len - 1): - if i > 0: result.add(sep) - result.add(t.sons[i].consToStr) +proc constraintsToStr(t: PType): string = + let sep = if tfAny in t.flags: " or " else: " and " + result = "" + for i in countup(0, t.len - 1): + if i > 0: result.add(sep) + result.add(t.sons[i].consToStr) proc TypeToString(typ: PType, prefer: TPreferedDesc = preferName): string = var t = typ @@ -446,7 +441,10 @@ proc TypeToString(typ: PType, prefer: TPreferedDesc = preferName): string = if t.len == 0: result = "typedesc" else: result = "typedesc[" & constraintsToStr(t) & "]" of tyTypeClass: - result = constraintsToStr(t) + case t.len + of 0: result = "typeclass[]" + of 1: result = "typeclass[" & consToStr(t.sons[0]) & "]" + else: result = constraintsToStr(t) of tyExpr: if t.len == 0: result = "expr" else: result = "expr[" & constraintsToStr(t) & "]"