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

let! doesn't infer return types #4

Closed
andriusch opened this issue Jan 13, 2020 · 3 comments
Closed

let! doesn't infer return types #4

andriusch opened this issue Jan 13, 2020 · 3 comments

Comments

@andriusch
Copy link

require "spectator"

def four
  2 + 2
end

Spectator.describe Int32 do
  let!(:x) { four }
  it("returns 4") { expect(x).to eq(4) }
end

Does not compile because crystal can't infer what type four returns. Strangely though if I replace let! with let it works fine and passes as it should. While I get why it doesn't compile with naive implementation of let!, you seem to have solved it with let, so it would be nice if it worked with let! too.

@icy-arctic-fox
Copy link
Owner

Yeah, sadly this fails because Crystal doesn't allow the following:

def four
  2 + 2
end

class Foo
  @var = four
end

There's actually a TODO in the code where this is a problem. I'll see what I can do to work around it.

@icy-arctic-fox
Copy link
Owner

Didn't mean to close this, but can you confirm that this is fixed in the latest version on master (0.9.2)? The code in your example works now. Hopefully that fixes any other issues with it that are non-trivial.

@andriusch
Copy link
Author

Yup it works now, very interesting way to bypass restrictions of crystal 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants