Skip to content
Critiq Docs

Search docs

Search documentation pages and rules

correctness.runtime

Initialize maps before assignment

Writing to a nil map panics at runtime.

#Metadata

Rule ID
go.correctness.nil-map-assignment
Severity
high
Confidence
0.85
Languages
go
Presets
strict
Stability
stable
Applies to
block
Tags
correctness, go, rules-catalog

#Why it matters

A `var m map[K]V` declaration leaves `m` nil. Any `m[key] = value` write before `make(map[K]V)` or a map literal initialization causes a runtime panic.

#Remediation

Initialize the map with `make(map[K]V)` or a map literal before writing to it.

#Repository path

The generated metadata points to critiq-rules/libs/rules/catalog/rules/go/go.correctness.nil-map-assignment.rule.yaml.