For memory-safety, this only seems problematic in case of closures, so I just special cased that. Fixes #25131