summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-rwxr-xr-xcompiler/types.nim48
1 files changed, 29 insertions, 19 deletions
diff --git a/compiler/types.nim b/compiler/types.nim
index 1c660958c..f3c54e2c5 100755
--- a/compiler/types.nim
+++ b/compiler/types.nim
@@ -393,26 +393,36 @@ proc rangeToStr(n: PNode): string =
   assert(n.kind == nkRange)
   result = ValueToString(n.sons[0]) & ".." & ValueToString(n.sons[1])
 
+const 
+  typeToStr: array[TTypeKind, string] = ["None", "bool", "Char", "empty", 
+    "Array Constructor [$1]", "nil", "expr", "stmt", "typeDesc", 
+    "GenericInvokation", "GenericBody", "GenericInst", "GenericParam", 
+    "distinct $1", "enum", "ordinal[$1]", "array[$1, $2]", "object", "tuple", 
+    "set[$1]", "range[$1]", "ptr ", "ref ", "var ", "seq[$1]", "proc", 
+    "pointer", "OpenArray[$1]", "string", "CString", "Forward",
+    "int", "int8", "int16", "int32", "int64",
+    "float", "float32", "float64", "float128",
+    "uint", "uint8", "uint16", "uint32", "uint64",
+    "bignum", "const ",
+    "!", "varargs[$1]", "iter[$1]", "Error Type", "TypeClass"]
+
 proc constraintsToStr(t: PType): string =
-  let sep = if tfAny in t.flags: " or " else: " and "
-  result = ""
-  for i in countup(0, t.sons.len - 1):
-    if i > 0: result.add(sep)
-    result.add(t.sons[i].typeToString)
+  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 TypeToString(typ: PType, prefer: TPreferedDesc = preferName): string = 
-  const 
-    typeToStr: array[TTypeKind, string] = ["None", "bool", "Char", "empty", 
-      "Array Constructor [$1]", "nil", "expr", "stmt", "typeDesc", 
-      "GenericInvokation", "GenericBody", "GenericInst", "GenericParam", 
-      "distinct $1", "enum", "ordinal[$1]", "array[$1, $2]", "object", "tuple", 
-      "set[$1]", "range[$1]", "ptr ", "ref ", "var ", "seq[$1]", "proc", 
-      "pointer", "OpenArray[$1]", "string", "CString", "Forward",
-      "int", "int8", "int16", "int32", "int64",
-      "float", "float32", "float64", "float128",
-      "uint", "uint8", "uint16", "uint32", "uint64",
-      "bignum", "const ",
-      "!", "varargs[$1]", "iter[$1]", "Error Type", "TypeClass"]
   var t = typ
   result = ""
   if t == nil: return 
@@ -433,12 +443,12 @@ proc TypeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
       add(result, typeToString(t.sons[i]))
     add(result, ']')
   of tyTypeDesc:
-    if t.sons == nil or t.sons.len == 0: result = "typedesc"
+    if t.len == 0: result = "typedesc"
     else: result = "typedesc[" & constraintsToStr(t) & "]"
   of tyTypeClass:
     result = constraintsToStr(t)
   of tyExpr:
-    if t.sons.len == 0: result = "expr"
+    if t.len == 0: result = "expr"
     else: result = "expr[" & constraintsToStr(t) & "]"
   of tyArray: 
     if t.sons[0].kind == tyRange: 
>
a4a99ae99 ^



550b5d9ae ^
a4a99ae99 ^
11b695875 ^
a4a99ae99 ^






43bddf62d ^
a4a99ae99 ^












11b695875 ^
771e3db86 ^
eb72857ea ^

a4a99ae99 ^
43bddf62d ^
4fbba0a65 ^
a4a99ae99 ^
11b695875 ^
a4a99ae99 ^
f66f43bca ^
a4a99ae99 ^
f66f43bca ^
a4a99ae99 ^

43bddf62d ^
a4a99ae99 ^

43bddf62d ^
a4a99ae99 ^







11b695875 ^
a4a99ae99 ^



11b695875 ^
a4a99ae99 ^
32109a786 ^
bf9764e56 ^
07b355bea ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97