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

Add Path#resolve? macro method #4408

Merged
merged 3 commits into from May 14, 2017

Conversation

RX14
Copy link
Contributor

@RX14 RX14 commented May 12, 2017

I think this is a useful feature, as most ASTNodes allow you to assert in some way whether the call you're about to make will raise, however Path#resolve does not.

Closes #4370.

@RX14
Copy link
Contributor Author

RX14 commented May 13, 2017

Just added a much cleaner implementation which doesn't rely on catching the thrown exception and inspecting it's message.

@mverzilli
Copy link

Would you add one or two lines of documentation? Documentation for macros is in src/compiler/crystal/macros.cr.

Btw, thanks for adding a couple of tests for resolve as well :).

@RX14
Copy link
Contributor Author

RX14 commented May 13, 2017

Oh! I forgot about the macro docs, silly me. I'll make sure to get that done.

unless matched_type
node.raise_undefined_constant(@path_lookup)
end
return unless matched_type

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be more explicit to return nil unless matched_type here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving out nil seems to be the more prevalent style so far, but there's quite a bit with nil too, and I don't mind either way. If we want to be consistent with return nil (if|unless), then maybe we should disallow not specifying it in the compiler (or formatter).

$ grep -ER 'return (unless|if)' src | wc -l
264
$ grep -ER 'return nil (unless|if)' src | wc -l
81

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an interesting stat! I tend to prefer more explicitness given early returning "generates" an union. Then when you get the famous "Nil does not respond to etc." it is easier to see how it can be Nil. But I guess my opinion on that is not as pervasive as I would have thought :(

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explicitness is noisy. Here nil is implied, just like return is implied when returning a value.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't agree in this case but one has to pick his fights :)

@RX14
Copy link
Contributor Author

RX14 commented May 14, 2017

I added some documentation, it should be ready to merge now.

@mverzilli mverzilli merged commit 5455664 into crystal-lang:master May 14, 2017
@mverzilli
Copy link

Thanks @RX14! 🙇

@mverzilli mverzilli added this to the Next milestone May 14, 2017
@Sija
Copy link
Contributor

Sija commented Jun 26, 2017

@mverzilli I think you can safely remove pr:needs-review label.

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.

Suggestion: Adding resolve? for macro Path
4 participants