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

Improve two errors #7542

Merged
merged 7 commits into from
May 15, 2019
Merged

Improve two errors #7542

merged 7 commits into from
May 15, 2019

Conversation

wooster0
Copy link
Contributor

This improves the error when you do for example pointerof(123) which can be fixed by putting 123 in a variable. That's needed because you can't just modify and operate on the raw value 123, that doesn't make sense. The value of a variable however can be modified.

And this also makes the stack overflow error slighlty more detailed to make sure there's no confusion. Even after stack overflow detection there was still some confusion about the error: #7032.

@bew
Copy link
Contributor

bew commented Mar 13, 2019

Also, it surprises me that pointerof(self) (and other pointerof(X) checks) is a parse error instead of a check done later in the processing of the parse tree.

@crystal-lang crystal-lang deleted a comment from straight-shoota Mar 13, 2019
@straight-shoota
Copy link
Member

@bew Only pointerof(self) is a parser error. self can't be a variable and it can't be used in pointerof, so its definitely an error at this stage.

Copy link
Member

@straight-shoota straight-shoota left a comment

Choose a reason for hiding this comment

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

Thanks, @r00ster91!

@bcardiff
Copy link
Member

Isn't it misleading that the message says

pointerof only works with variables

but pointerof(obj.@ivar) and pointerof(LibFoo.external_var) are allowed?

@wooster0
Copy link
Contributor Author

wooster0 commented May 15, 2019

The error message doesn't specify what kind of variable. It could be for example an instance variable, a class variable or an external variable. It would be misleading if it would say "local variables".

@asterite
Copy link
Member

I agree with @bcardiff . It's misleading because at the syntax level obj.@ivar and LibFoo.external_var don't look like variables, even though they point to variables.

What's wrong with the current error message?

@wooster0
Copy link
Contributor Author

What's wrong with the current error message?

I don't think there's something wrong with the error. I think at the syntax level obj.@ivar isn't confusing because you can clearly see that it's an instance variable. Same for LibC.variable. If you know that it's a variable, the error makes sense. The error doesn't specify what kind of variable it needs to be, it can be any variable.

@asterite
Copy link
Member

People usually read "variable" as "local variable". Ask anyone "what's a variable in Ruby" and they will say "the 'x' in 'x = 1'". They will never say "oh, and variable could also mean instance or class variable".

I think, if it's not broken, we shouldn't fix it.

@wooster0
Copy link
Contributor Author

Okay but maybe at least turn can't take pointerof(self) into can't take address of self for consistency with the other errors then?

@Sija
Copy link
Contributor

Sija commented May 15, 2019

I vote to close this PR.

@wooster0
Copy link
Contributor Author

@Sija why? I'm trying to do something out of this PR.

@Sija
Copy link
Contributor

Sija commented May 15, 2019

@r00ster91 because the actual error message is imo good enough.

@asterite asterite merged commit 42783b7 into crystal-lang:master May 15, 2019
@asterite asterite added this to the 0.29.0 milestone May 15, 2019
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.

6 participants