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

Change Foo:Class representation of Class types to Foo.class #6439

Merged
merged 1 commit into from Jul 29, 2018

Conversation

RX14
Copy link
Contributor

@RX14 RX14 commented Jul 24, 2018

Using the Foo.class representation of class types in error messages matches the
type syntax used to write these types, instead of using a special and confusing
syntax unique to compiler error messages.

For example:

class variable '@@foo' of Bar must be Hash(Thing:Class, String), not Hash(Thing, String)

becomes

class variable '@@foo' of Bar must be Hash(Thing.class, String), not Hash(Thing, String)

which means the type is now represented exactly the same way in the error
messages as source code.

Using the Foo.class representation of class types in error messages matches the
type syntax used to write these types, instead of using a special and confusing
syntax unique to compiler error messages.

For example:

class variable '@@foo' of Bar must be Hash(Thing:Class, String), not Hash(Thing, String)

becomes

class variable '@@foo' of Bar must be Hash(Thing.class, String), not Hash(Thing, String)

which means the type is now represented exactly the same way in the error
messages as source code.
@@ -38,7 +38,7 @@ end

class Crystal::Call
def raise_matches_not_found(owner, def_name, arg_types, named_args_types, matches = nil, with_literals = false)
# Special case: Foo+:Class#new
# Special case: Foo+.class#new
Copy link
Member

Choose a reason for hiding this comment

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

This is not exactly source code syntax, but it looks as if...

Copy link
Contributor Author

@RX14 RX14 Jul 24, 2018

Choose a reason for hiding this comment

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

The + syntax is a different issue. This is closer and so an improvement.

@straight-shoota
Copy link
Member

Just an idea: Java uses generics Class<Foo>, which would be Class(Foo) in Crystal. Crystal's Class type isn't generic, but maybe it could be a good representation? Class(Foo+) would at least make more sense than Foo+.class.

@RX14
Copy link
Contributor Author

RX14 commented Jul 24, 2018

@straight-shoota but that would require changing the whole language, this is just about changing the error messages / string representation inside the compiler to be more consistent with the existing syntax.

@straight-shoota
Copy link
Member

I wasn't suggesting to change the language. Just an idea though. This PR is certainly an improvement 👍

@RX14
Copy link
Contributor Author

RX14 commented Jul 28, 2018

@asterite is there any reason this was like this in the first place?

@asterite
Copy link
Member

Ruby

@sdogruyol
Copy link
Member

sdogruyol commented Jul 28, 2018

This is a small but an important improvement over the current behavior. Just this week alone I had to explain why the compiler error had Hash(Thing:Class) instead of the actual type 🤦‍♂️

Copy link
Member

@sdogruyol sdogruyol left a comment

Choose a reason for hiding this comment

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

Thank you @RX14 👍

@RX14 RX14 merged commit 665b18c into crystal-lang:master Jul 29, 2018
@RX14 RX14 modified the milestones: Next, 0.26.0 Jul 29, 2018
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.

None yet

4 participants