compiler: implement operations on nil hashmaps

* comparing a map against nil
  * getting the length of a nil map
This commit is contained in:
Ayke van Laethem
2018-10-27 00:54:13 +02:00
parent c84fc6a670
commit 436901dc49
4 changed files with 31 additions and 7 deletions
+5
View File
@@ -26,6 +26,11 @@ func main() {
readMap(testmap2, "seven")
lookup(testmap2, "eight")
lookup(testmap2, "nokey")
// operations on nil maps
var nilmap map[string]int
println(m == nil, m != nil, len(m))
println(nilmap == nil, nilmap != nil, len(nilmap))
}
func readMap(m map[string]int, key string) {
+2
View File
@@ -48,3 +48,5 @@ map read: seven = 7
twelve = 12
lookup with comma-ok: eight 8 true
lookup with comma-ok: nokey 0 false
false true 2
true false 0