question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[error] knownDirectSubclasses of ... observed before subclass ... registered

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
briangordoncommented, Sep 11, 2017

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.

3reactions
sirthiascommented, Jun 23, 2017

Nesting the ADT “cases” in the super types companion object, as is a popular name spacing technique, appears to trigger this problem. For instance

sealed trait Foo
object Foo {
  case object AFoo extends Foo
  case object BFoo extends Foo
}
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found