summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2021-02-08 04:45:06 -0800
committerGitHub <noreply@github.com>2021-02-08 13:45:06 +0100
commit910720b0d44721b1c467b23227ec77467b80c633 (patch)
tree73d6b147421240a57ac7cc42245bde9ae9561db2
parent0cf3ba159c97d3aa00bcb408e99cd4bdef33d64f (diff)
downloadNim-910720b0d44721b1c467b23227ec77467b80c633.tar.gz
document typeof (#16965)
-rw-r--r--lib/system.nim19
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/system.nim b/lib/system.nim
index 888217493..508978521 100644
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -251,8 +251,23 @@ when defined(nimHasTypeof):
     magic: "TypeOf", noSideEffect, compileTime.} =
     ## Builtin `typeof` operation for accessing the type of an expression.
     ## Since version 0.20.0.
-    discard
-
+    runnableExamples:
+      proc myFoo(): float = 0.0
+      iterator myFoo(): string = yield "abc"
+      iterator myFoo2(): string = yield "abc"
+      iterator myFoo3(): string {.closure.} = yield "abc"
+      doAssert type(myFoo()) is string
+      doAssert typeof(myFoo()) is string
+      doAssert typeof(myFoo(), typeOfIter) is string
+      doAssert typeof(myFoo3) is "iterator"
+
+      doAssert typeof(myFoo(), typeOfProc) is float
+      doAssert typeof(0.0, typeOfProc) is float
+      doAssert typeof(myFoo3, typeOfProc) is "iterator"
+      doAssert not compiles(typeof(myFoo2(), typeOfProc))
+        # this would give: Error: attempting to call routine: 'myFoo2'
+        # since `typeOfProc` expects a typed expression and `myFoo2()` can
+        # only be used in a `for` context.
 
 const ThisIsSystem = true
 
15:09 +0200 Rework JS exception system' href='/ahoang/chawan/commit/src/utils/opt.nim?id=17097052794aef56bbc55327d3e6c84ae1c67378'>17097052 ^
81576783 ^
4e0fd8c7 ^
17097052 ^


4e0fd8c7 ^
81576783 ^
4e0fd8c7 ^
81576783 ^




4e0fd8c7 ^

17097052 ^



4e0fd8c7 ^
81576783 ^


17097052 ^





4e0fd8c7 ^

81576783 ^

17097052 ^









81576783 ^
17097052 ^
81576783 ^








82fb1f70 ^
81576783 ^


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
98
99
100