Skip to content

Commit 69d6f9e

Browse files
authored
docs(nil): 细化示例的歧义,修正示例代码缩进 (#56)
1 parent 1c36823 commit 69d6f9e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/essential/impl/err/3.nil.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
type A struct {
99
b B
1010
c C
11-
d D
11+
d D
1212
}
1313

1414
func (a A) Close() error {
@@ -197,14 +197,18 @@ func main() {
197197
}
198198
```
199199

200-
当 map 为`nil`的时候,还可以对其进行访问
200+
当 map 为`nil`的时候,还可以对其进行访问,但`nil`的 map 是只读的,一旦尝试写入就会引发panic
201201

202202
```go
203203
func main() {
204204
var s map[string]int
205205
i, ok := s[""]
206206
fmt.Println(i, ok)
207207
fmt.Println(len(s))
208+
209+
// 尝试写入时,会引发panic
210+
s["a"] = 1 // panic: assignment to entry in nil map
211+
208212
}
209213
```
210214

0 commit comments

Comments
 (0)