-
Notifications
You must be signed in to change notification settings - Fork 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 #17201: do no call ensureCompleted for import symbol #17304
Draft
dos65
wants to merge
1
commit into
scala:main
Choose a base branch
from
dos65:export_cyclic_ref_fix
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// cycle/Cycle.scala | ||
package cycle: | ||
import scala.concurrent.Future | ||
|
||
object Cycle: | ||
given heyInt: Future[Int] = ??? | ||
|
||
// cycle/package.scala | ||
package object cycle: | ||
export Cycle.heyInt |
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.
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.
This could typecheck an expression in a context which has
NoSymbol
as owner, which will cause havoc ifimp
has any local symbols.I think we need to dig deeper. Either accept the cyclic error but avoid
<import>
in the error message or somehow heal the situation. But I disagree that aNotFound
is necessarily better. I think it could be more puzzling than the cyclic error.Generally, I think trying
export
for package management is doomed. Even if it worked, I would find it dubious since it would just add another layer of complexity.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.
That's a pity, because it seems that people naturally tend to use that way (as in https://contributors.scala-lang.org/t/why-the-current-export-is-problematic-for-import/6147), and because cyclic errors involving exports might not mention export/import at all, like in #17076, where the problem suddenly started manifesting itself long after the user had started using export, making it extremely hard to debug.
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.
Yes, I think the best thing to do now is warn people that that's an anti-pattern.
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.
Thanks.
I will look at that a bit more.
Having an explanation from @smarter I'm wondering if we can also try to trigger package completion (which includes package export) in advance before visiting first first import. In theory it should change the completion order and at least fix #17201
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 believe any change in the order would cause other cycles. This whole thing (trying to avoid cycles) is very, very finely balanced. And it is also what it is, by now. Any change in the order would likely reject existing code, and therefore is infeasible at this point.
One can delay evaluation at some point if one can arrange things that certain info is not needed at this point and can be accessed later. For instance, a recent change of mine moved some checks to PostTyper, since they needed info that caused cycles in Typer. But I don't think that's applicable for exports.
The other room for improvement is in better diagnostics if there is a CyclicReference. I believe there is still a lot to be done, but it is not easy.
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 don't think this is a behavior change from what happened before,
retrieveSym
can also return NoSymbol, but import qualifiers don't define new symbols so I'm not sure thatwithOwner
does anything anyway.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've just run into an error likely caused by this -
What would you consider the use of export other than package management?
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.
According to https://docs.scala-lang.org/scala3/reference/other-new-features/export.html#motivation, the point of export is to make it easier to choose composition over inheritance. See also historical discussions https://contributors.scala-lang.org/t/request-for-comments-on-exports/4051 and https://contributors.scala-lang.org/t/having-another-go-at-exports-pre-sip/2982