TGViewer
igoroutine.courses igoroutine.courses @igoroutine_courses · 239 subscribers
Post #18 277

Forwarded from Igor Panasyuk | IGORoutine Programming

Что будет выведено в stdout?

С точки зрения стандарта языка:
The comparison operators == and != must be fully defined for operands of the key type; thus the key type must not be a function, map, or slice. If the key type is an interface (то есть any) type, these comparison operators must be defined for the dynamic key values; failure will cause a run-time panic.

В текущем случае тип Key это произведение типов int и func. Поскольку в произведении типов присутствует тип func, то
Key не имеет операторов сравнения != и ==. Поэтому, согласно стандарту, получаем панику:

panic: runtime error: hash of unhashable type main.Key

https://go.dev/play/p/YgAgjKr6Jhp
go.dev Go Playground - The Go Programming Language
  • 🔥 7
  • ❤ 4
  • ✍ 1
More from @igoroutine_courses
  1. Jun 25, 2026Разбор задачи с порядком вызова функций в select Что будет выведено в stdout после запуска…
  2. Jun 24, 2026Post #40
  3. Jun 24, 2026photo post
  4. Mar 24, 2026😎😎 Это изменение сломало set на map[key]struct{}, который мы знали Продолжение предыдуще…
  5. Mar 23, 2026😎😎 Это изменение сломало Set на map[key]struct{}, который мы знали В Go все привыкли пис…
  6. Mar 5, 2026😎😎 От этого data race не спасает даже race detector Продолжение к предыдущему посту. Ита…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →