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

Switch conditional order since 'void' is a primitive class. #109

Merged
merged 1 commit into from
Dec 6, 2014

Conversation

JakeWharton
Copy link
Member

No description provided.

@tbroyer
Copy link
Collaborator

tbroyer commented Dec 6, 2014

If void is a primitive type, should we rather move to PrimitiveName.VOID instead of VoidName.VOID?

@JakeWharton
Copy link
Member Author

Possibly. When you say Java primitives types I'm willing to bet almost everyone only lists the 8 value types. So it's whether we want to be exactly correct or more semantically correct.

Thoughts @gk5885?

@eamonnmcmanus
Copy link
Contributor

The area is kind of murky. The JLS does not consider void to be a type at all, but merely says that a method has a Result, which can be either a type or void. On the other hand, given the precedent of Class.isPrimitive() and the nine boxed types in java.lang, perhaps the simplest thing would indeed to get rid of VoidName and add a ninth value to PrimitiveName. Alternatively, we could deal with void properly in the type system by having the returnType parameter to the MethodWriter constructor be a TypeNameOrVoid or an Optional<TypeName>, thus making it a compile-time failure to try to use void anywhere else (for a field or a parameter or a local variable).

@tbroyer
Copy link
Collaborator

tbroyer commented Dec 6, 2014

@eamonnmcmanus Add to that that void is a NoType in javax.lang.model.type. So I think that void.class.isPrimitive() is an unfortunate legacy, and we should probably keep the VoidName (I think the TypeNameOrVoid would unnecessarily complicate things).

In other words, LGTM.

@eamonnmcmanus
Copy link
Contributor

What about Optional<TypeName> for specifying the returnType of a MethodWriter, or a second constructor with no returnType parameter? I think it's a little unfortunate that the current model allows you to ask for a void field or parameter, when it could so easily not.

@JakeWharton
Copy link
Member Author

@eamonnmcmanus Want to open an issue for that? Since this PR is just fixing the existing behavior I'm going to go ahead and merge (especially since it's blocking me).

JakeWharton added a commit that referenced this pull request Dec 6, 2014
Switch conditional order since 'void' is a primitive class.
@JakeWharton JakeWharton merged commit 0572bbf into master Dec 6, 2014
@JakeWharton JakeWharton deleted the jw/check-void-first branch December 6, 2014 23:26
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

Successfully merging this pull request may close these issues.

None yet

3 participants