From 61dc7fe30d16b920888123390c6965614e491a66 Mon Sep 17 00:00:00 2001 From: Vladimir Varankin Date: Mon, 15 Sep 2025 17:04:04 +0000 Subject: [PATCH] iter: document that calling yield after terminated range loop causes runtime panic The existing documentation isn't clear about the behaviour of when the iterator function ignores the value returned from the yield function. The changes here update the documentation, to explicitly explain that. Change-Id: I24a8198c3da63429358554169697fa466345b8fd GitHub-Last-Rev: 86c8a2dd89dca4e05631f5c4f7087b59b0e0664b GitHub-Pull-Request: golang/go#74561 Reviewed-on: https://go-review.googlesource.com/c/go/+/687215 Auto-Submit: Sean Liao Reviewed-by: Sean Liao Reviewed-by: Michael Knyszek LUCI-TryBot-Result: Go LUCI Reviewed-by: Mark Freeman --- src/iter/iter.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/iter/iter.go b/src/iter/iter.go index 3eaeb9e1fd..3d0caebf1e 100644 --- a/src/iter/iter.go +++ b/src/iter/iter.go @@ -28,6 +28,8 @@ or index-value pairs. Yield returns true if the iterator should continue with the next element in the sequence, false if it should stop. +Yield panics if called after it returns false. + For instance, [maps.Keys] returns an iterator that produces the sequence of keys of the map m, implemented as follows: -- 2.52.0