Skip to content

Fix yielding block return type restriction underscore#10929

Closed
straight-shoota wants to merge 1 commit intocrystal-lang:masterfrom
straight-shoota:fix/block-return-underscore
Closed

Fix yielding block return type restriction underscore#10929
straight-shoota wants to merge 1 commit intocrystal-lang:masterfrom
straight-shoota:fix/block-return-underscore

Conversation

@straight-shoota
Copy link
Member

There's an unintended subtle difference for yielding blocks and underscore return value.
See #10467 (comment)

This patch replaces all underscore return types in yielding block parameters to avoid potential issues with that. This is essentially a workaround for wanky compiler behaviour.

Related to #10928

There's an unintended subtle difference for yielding blocks and
underscore return value.
See
crystal-lang#10467 (comment)
@straight-shoota straight-shoota added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib labels Jul 13, 2021
@asterite
Copy link
Member

I think this is wrong. Underscore means anything can be returned. Omission of a type means Nil. Maybe omission should mean anything, but too late.

@asterite
Copy link
Member

I'm surprised this isn't failing. Can I fix the underlying issue instead? Block restrictions work a bit different if a block is captured or not.

@asterite
Copy link
Member

Of course to fix this I first need to understand the problem. Could you describe what this is solving?

@asterite
Copy link
Member

Okay, I think I understand now. A bug should have been reported instead of just a mention in the forums.

I can try fixing underscore for the NoReturn case.

@asterite
Copy link
Member

Here we go: #10933

I think the fix should be pretty safe. It's doing less work than before if the return type is an underscore. There's probably no way this introduced a regression.

@straight-shoota
Copy link
Member Author

Yes, this might be wrong as it's not the syntax we would ideally want to use.

But it makes sure things work with the current compiler semantics. Nil return type of yielding block parameters is currently not casted to Nil but passed through:

def foo(& : ->)
  yield
end

foo { 1 } # => 1

Maybe it should. We can discuss that in #10931.

beta-ziliani pushed a commit that referenced this pull request Jul 13, 2021
@straight-shoota
Copy link
Member Author

With #10933 being merged these changes are not necessary and mostly unintended when the output values of the block parameter are being used (see #10931 (comment)).

I'll create a new PR for any intended changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants