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

NilLiteral.nil? return false #10534

Closed
erdnaxeli opened this issue Mar 22, 2021 · 1 comment · Fixed by #10616
Closed

NilLiteral.nil? return false #10534

erdnaxeli opened this issue Mar 22, 2021 · 1 comment · Fixed by #10616
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:parser topic:lang:macros

Comments

@erdnaxeli
Copy link
Contributor

erdnaxeli commented Mar 22, 2021

Hi,

As the title says:

{% puts nil.nil? %}

false

I am not sure this is a bug, NilLiteral is not nil, but it feels weird.

Tested with 0.36.1, as 1.0.0 is not yet available on playgrounds.

@erdnaxeli erdnaxeli added the kind:bug A bug in the code. Does not apply to documentation, specs, etc. label Mar 22, 2021
@straight-shoota
Copy link
Member

The parser transforms nil.nil? to nil.is_a?(Nil). In regular code that is correct and works as expected. But in the macro language the type of nil is NilLiteral and .is_a?(Nil) returns false.

I don't think .nil? was ever intended for the macro language. It just happens to be accepted by the compiler because of the implicit transform to IsA.

We could fix the behaviour or let .nil? be undefined in the macro language.

It's not really necessary there. The reason for .nil? in the regular language is to provide a reliably way for the compiler to identify nil types without the equality operator which can be overriden in user code.
But in the macro language that's not an issue anyways, so every x.nil? could just be written as x == nil.

It doesn't seem that .nil? is used that much in macro expressions anyways, otherwise it should have long been noticed that it's completely broken.

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:compiler:parser topic:lang:macros
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants