Cyclic reference of extension method when exported and used at toplevel
See original GitHub issueCompiler version
v3.1.0-RC2
Minimized code
https://scastie.scala-lang.org/upOXnTlLTgaIZoVUhlsMGg
trait MyExtensions:
extension (lhs: Int) def bash: Unit = {}
object MyExtensions extends MyExtensions
object Internal:
export MyExtensions.*
val works = 1.bash
export MyExtensions.*
val fails = 1.bash
Output
-- [E046] Cyclic Error: test.scala:2:18 -------------------------------------------
2 | extension (lhs: Int) def bash: Unit = {}
| ^
| Cyclic reference involving method bash
longer explanation available when compiling with `-explain`
-- [E008] Not Found Error: test.scala:11:14 ---------------------------------------
11 |val fails = 1.bash
| ^^^^^^
| value bash is not a member of Int
Expectation
No error. Note: if used in scastie in Worksheet mode, this example compiles successfully.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
scala - Top level opaque type with same underlying type and ...
I ran into an issue when defining opaque types with identical underlying types and extension methods, e.g.: opaque type HandleA = Int object ......
Read more >Extension method must be defined in a top level static class
Hi All,. I am trying to understanding extension method and it uses. So i wrote below code at C#.Net-4.7 sdk.
Read more >Dart Static Extension Methods Design - language - GitHub
The extension methods are static, which means that we use the static type of an expression to figure out which method to call,...
Read more >16. Modules - Exploring JS
Imports and exports must be at the top level; 16.3.4. Imports are hoisted; 16.3.5. Imports are read-only views on exports; 16.3.6. Support for...
Read more >Extension Methods - Scala 3 - EPFL
The extension method is visible under a simple name, by being defined or inherited or imported in a scope enclosing the reference. The...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you very much @smarter and @odersky !
As a workaround, you can move the object definition ahead of the trait definition:
I’m also reopening since I have a tentative fix: https://github.com/lampepfl/dotty/pull/13719