Skip to content

Fix #1648: don't define companion object for java.lang.Object #1724

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

Merged
merged 1 commit into from
Nov 18, 2016

Conversation

liufengyun
Copy link
Contributor

@liufengyun liufengyun commented Nov 17, 2016

Fix #1648: java.lang.Object has no static methods, there's no need to define module object for it.

@liufengyun liufengyun changed the title fix #1648: don't define companion object for java.lang.Object Fix #1648: don't define companion object for java.lang.Object Nov 17, 2016
@liufengyun
Copy link
Contributor Author

It seems the fix works. I'm not sure if it's the right way to do it. Could you please advise, @odersky ?

modFlags = flags.toTermFlags & RetainedModuleValFlags,
clsFlags = flags.toTypeFlags & RetainedModuleClassFlags,
scope = scope)

Copy link
Contributor

Choose a reason for hiding this comment

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

It's a way to do it, but not very elegant to test this for every class and module that's entered.

I played with an alternative strategy, which also seems to work and is less intrusive: IN line 196 of Definitions, where we define ObjectClass, insert:

val companion = JavaLangPackageVal.info.decl(nme.Object).symbol
companion.info = NoType // to indicate that it does not really exist

Copy link
Contributor

Choose a reason for hiding this comment

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

Note: The NoType technique is not an accident. It is used for all companion objects that are entered (because we see their file name) but turn out to not exist after class loading. Here we have to do it before class loading because once we try to load Object's classfile it is already too late.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @odersky , this is much more elegant 👍 . I've pushed a new commit adopting the approach.

@odersky
Copy link
Contributor

odersky commented Nov 18, 2016

LGTM

@odersky odersky merged commit 601a286 into scala:master Nov 18, 2016
liufengyun added a commit to dotty-staging/dotty that referenced this pull request Mar 14, 2017
The bug is already fixed in PR scala#1724 while fixing another issue
@liufengyun liufengyun mentioned this pull request Mar 14, 2017
liufengyun added a commit to dotty-staging/dotty that referenced this pull request Mar 14, 2017
The bug is already fixed in PR scala#1724 while fixing another issue
@allanrenucci allanrenucci deleted the fix-i1648 branch December 14, 2017 19:20
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.

3 participants