-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Cyclic reference of extension method when exported and used at toplevel #13669
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
Comments
I don't see a reason to fix this. Cyclic References are a possibility. So to classify as a bug you'd have to argue that the particular CyclicReference should not happen and can be avoided. You can ask why it does work if the export is in an explicit object. That's a good question. to ask and answer |
We want users to have fun coding in Scala is a good enough reason for fixing, IMO. Yet another inconsistent limitation that causes an error that gives no clue to the actual reason for the error is not the way to achieve it. |
Right, but my time is limited and I do already the best I can and more. If people want this fixed then they have to step up and fix it! Right now I see a steady increase of issues some of which are marginal. This means that important issues are more likely to be overlooked. |
As far as I can tell the cycle looks like this:
But I'm not sure why it compiles fine if the method is defined in the object directly instead of in a parent trait: object MyExtensions:
extension (lhs: Int) def bash: Unit = {}
export MyExtensions.bash
val fails = 1.bash It seems like that changes the order in which we complete things (export -> definition rather than definition -> export -> definition) |
Keeping an issue open does not mean YOU need to fix it. If it's something that we can agree requires a fix, then keep the issue open. If it's a low priority, then just tag it as |
I agree it's not me who has to fix it. But I see nobody else doing it either at present. And the more open bugs the less efficient people signing up to fix them will be. Now this one is an issue where it is not clear whether it is a bug or not. It's an interesting question why one produces a cycle and the other does not. But in general cycles are to be expected for this kind of code. So I prefer we do not clog the bug pipeline and our own limited mental capacity to figure it out. If someone wants to do it on the side, great! But until we known more, it's a puzzle, not a bug that needs fixing. |
As a workaround, you can move the object definition ahead of the trait definition: object MyExtensions extends MyExtensions
trait MyExtensions:
extension (lhs: Int) def bash: Unit = {}
export MyExtensions.*
val fails = 1.bash I'm also reopening since I have a tentative fix: #13719 |
Compiler version
v3.1.0-RC2
Minimized code
https://scastie.scala-lang.org/upOXnTlLTgaIZoVUhlsMGg
Output
Expectation
No error.
Note: if used in scastie in Worksheet mode, this example compiles successfully.
The text was updated successfully, but these errors were encountered: