Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support explicit return types in ProcLiterals #11402

Conversation

HertzDevil
Copy link
Contributor

Resolves #11218.

A ProcLiteral with an explicit return type can now be used to type instance and class variables:

class Foo
  getter foo = ->(x : Int32) : Int32 {
    return x // 2 if x.even? # okay
    x * 3 + 1
  }

  # current way:
  getter bar = Proc(Int32, Int32).new { |x|
    next x // 2 if x.even?
    x * 3 + 1
  }
end

The corresponding macro method accessor is ProcLiteral#return_type.

@oprypin oprypin self-requested a review November 3, 2021 17:57
@straight-shoota straight-shoota added this to the 1.3.0 milestone Nov 11, 2021
@straight-shoota straight-shoota merged commit fe810b3 into crystal-lang:master Nov 15, 2021
@HertzDevil HertzDevil deleted the feature/proc-literal-return-type branch November 15, 2021 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Explicit return types for Proc literals
3 participants