magnolia
magnolia copied to clipboard
Better error messages
This is probably a large issue, with multiple improvements that can be done.
For example, when removing the given Print[Int] = _.toString from the readme example, the error message is:
[error] -- [E008] Not Found Error: Test.scala:33:77
[error] 33 | println(Tree.Branch(Tree.Branch(Tree.Leaf(1), Tree.Leaf(2)), Tree.Leaf(3)).print)
[error] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error] |value print is not a member of Test.Tree.Branch[Int].
[error] |An extension method was tried, but could not be fully constructed:
[error] |
[error] | Test.Tree.derived$Print[T](
[error] | Test.Print.derived[A](
[error] | /* missing */
[error] | summon[
[error] | deriving.Mirror{
[error] | MirroredType >: Int; MirroredMonoType >: Int;
[error] | MirroredElemTypes <: Tuple
[error] | }
[error] | ]
[error] | )
[error] | ).print()
[error] one error found
Maybe we could do better here?
Currently derivations often fail with messages like:
cannot reduce summonFrom with (...)
TODO: example
Promised example, using the classes from tests:
case class Param(a: String, b: String)
case class TestEntry(param: Param)
When you do:
SemiPrint.derived[TestEntry].print(TestEntry(Param("a", "b")))
you get:
[error] -- Error: /Users/adamw/projects/magnolia/src/test/tests.scala:234:14 -----------
[error] 234 | val res = SemiPrint.derived[TestEntry].print(TestEntry(Param("a", "b")))
[error] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error] |cannot reduce summonFrom with
[error] | patterns : case given t @ _:magnolia.examples.SemiPrint[magnolia.tests.Param]
[error] | This location contains code that was inlined from package.scala:140
[error] | This location contains code that was inlined from magnolia.scala:52
[error] | This location contains code that was inlined from magnolia.scala:13
[error] | This location contains code that was inlined from magnolia.scala:88
[error] | This location contains code that was inlined from magnolia.scala:90
[error] one error found
Which could be better :)