-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
fix(#17255): cannot find Scala companion module from Java #19773
Merged
bishabosha
merged 7 commits into
scala:main
from
i10416:fix/cannot-find-companion-module-in-java
Feb 28, 2024
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
22d98d6
fix: cannot find Scala companion module from Java
i10416 4cb34e5
tweak: try the original name first and then fallback to module
i10416 4992b4b
Update compiler/src/dotty/tools/dotc/core/ContextOps.scala
i10416 1d65c5b
fix: imported symbol missing for companion module
i10416 d84b3ca
test: add a test to confirm scala/scala#10644 is forward-ported
i10416 cbfdf57
fix(test): skip a test to avoid linking error due to java source
i10416 96c91da
Apply suggestions from code review
i10416 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,3 +44,5 @@ t6138 | |
t6138-2 | ||
i12656.scala | ||
trait-static-forwarder | ||
i17255 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package example; | ||
|
||
|
||
public class Bar { | ||
private static final example.Foo$ MOD = example.Foo$.MODULE$; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package example; | ||
|
||
import example.Foo$; | ||
|
||
public class Baz { | ||
private static final Foo$ MOD = Foo$.MODULE$; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package example | ||
|
||
case class Foo(i: Int) | ||
|
||
object Foo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package p; | ||
|
||
public class J { | ||
public static J j = new J(); | ||
public static p.J f() { | ||
return p.J.j; | ||
} | ||
public static p.Module$ module() { | ||
i10416 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return p.Module$.MODULE$; | ||
} | ||
|
||
public String toString() { return "J"; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// scalajs: --skip | ||
|
||
package p { | ||
object Module { | ||
override def toString = "Module" | ||
} | ||
} | ||
|
||
object Test extends App { | ||
assert(p.J.f().toString == "J") | ||
assert(p.J.module().toString == "Module") | ||
i10416 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the tree reaches TASTy, this looks like
really, tree
91
should beSELECTtpt 19 [Module[ModuleClass]]
.It would be very nice to perhaps also replace
typeName("Module$")
withtypeName("Module").moduleClassName
intypedSelect
inTyper
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can leave this to follow-up, as it is still better than status quo. However this does rely on the compiler (aka all TASTy clients) intrinsically knowing how to resolve
Module$
when the definition is actuallyModule[ModuleClass]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new issue #19806
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for reviewing. I will investigate #19806 too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with TASTy, so it may take a while...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way to solve this is in
typedSelect
replacing the name in theSelect
tree, in the same way you did injavaFindMember
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can I test TASTy?(or make sure
SELECTtpt 17 [Module$]
is replaced withSELECTtpt 19 [Module[ModuleClass]]
because testp/pos does not seem to detect the difference...)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can do it manually with the
-Yprint-tasty
flag which will print to the console any generated TASTy after pickler phase, make sure you use the required-Yjava-tasty
also so that you generate tasty for java sources