commercetools / commercetools/sphere-scala-libs
Support hierarchies with cyclical dependencies
- Dominant language
- Scala
- Stars
- 22
- Forks
- 7
- Avg merge
- 18h 43m
- Merged PRs (30d)
- 20
Description
``` scala
sealed trait Parent
case class A(b: B) extends Parent
case class B(foo: String) extends Parent
```
This _may_ go wrong depending on which (random? alphabetical?) order the subclasses are detected because the macro then generates code containing a forward reference. I'm not sure how easy this is to fix. I know the Play JSON macro has a mechanism for warning of such cases (i.e. it fails if it can't find an implicit JSON format in scope), one idea would be to take into account the order of declaration of the subclasses in code by doing a tree traversal and sort the subclasses discovered at compile-time according to that order (but I don't know how easy that is, I have only a limited experience with macros). Or another approach could be to do a [topological sort](http://en.wikipedia.org/wiki/Topological_sorting) on the subclasses should they reference symbols that are also subclasses of the trait.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the Scala macro's subclass-detection and generated-code path described in the issue, using the A/B hierarchy as the reproduction case. Compare the discovered subclass order and check the Play JSON macro's warning behavior as a reference. Done means cyclical subclass dependencies no longer produce invalid forward references, with the behavior covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100