[error] knownDirectSubclasses of ... observed before subclass ... registered
See original GitHub issueI have a simple ADT setup:
sealed trait KeyStoreLocation
final case class Resource(path: String) extends KeyStoreLocation
final case class File(path: String) extends KeyStoreLocation
This type is used as a member of another case-class that I load via pureconfig. It seemed to work, but then after a while it stopped compiling:
[error] knownDirectSubclasses of KeyStoreLocation observed before subclass Resource registered
[error] knownDirectSubclasses of KeyStoreLocation observed before subclass File registered
What is weird that I have not changed any of the classes involved here! It seems like a compilation order issue to me, but I don’t know how to fix it.
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (3 by maintainers)
Top Results From Across the Web
knownDirectSubclasses of <class> observed before subclass ...
I believe knownDirectSubclass is used by shapeless to compute all the subclasses of a sealed trait. This https://github.com/circe/circe- ...
Read more >How to avoid knownDirectSubclasses errors in Scala 2.12.4+?
[error] knownDirectSubclasses of FileCommand observed before subclass ExecFile registered [error] one error found [error] ...
Read more >typelevel/scala - Gitter
[error] knownDirectSubclasses of Foo observed before subclass A registered [error] knownDirectSubclasses of Foo observed before subclass B ...
Read more >Scala reflection: knownDirectSubclasses only works for ...
Good question! I checked and adding a declaration + println for Baz() and Bar() doesn't make any difference. – helgridly. Dec 3, 2015...
Read more >Warnings and known issues - circe
... automatic derivation, you may have run into an error that looks like this: knownDirectSubclasses of <class> observed before subclass <class> registered.
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
Note for people who are googling this… this bug should be fixed in Scala 2.12.4 (scala/scala#6029)
In the meantime one easy workaround is to rename the file containing your ADT to have “AA” in front of the filename. That rejiggers the lexicographical order of the filenames and the compiler stops complaining.
Nesting the ADT “cases” in the super types companion object, as is a popular name spacing technique, appears to trigger this problem. For instance