Skip to content

Continue with anonymous block arguments #8764

Open
@straight-shoota

Description

Follows up on #8117. This PR added syntax for anonymous block arguments def foo(&). The idea is to use this syntax exclusively for yielding methods.
Currently it's valid to completely omit the block argument when there's yield in the body. This hides the yielding nature of the method from the signature and API docs. Such an essential property should be made visible.

After the initial syntax was added, we switched usage in stdlib in #8394.

The next step would be to deprecate some of the currently valid method signatures. The idea as proposed in #8117:

  • Just & means a non-captured block argument: because it doesn't have a name there's no way to capture it
  • &block means a captured block argument, and the compiler will verify that it's used in the semantic phase (because it might be mentioned inside a macro)
  • &block without a mention will give a compile error suggesting to either change it to & to avoid a closure or to mention it somehow
  • if you yield and the method signature doesn't have & the compiler will tell you

This would be a breaking change for yielding methods with a named block argument or no block argument at all, and also for methods with a named block argument that's never used in the literal scope of its body. But it improves clarity and helps to better identify the behaviour of block arguments.

Part of #7157

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions