问题
Most of the time, all you get is an implicit not found error. You don't know where in the chain of implicit construction it failed. Apparently you can't use runtime debug or print statement. So how do you debug type-level program other than staring at your code really hard?
回答1:
I wish I had a better answer, but here it goes: Start passing the parameters explicitly, one at a time until it gives you a more useful error. (adding-prinlns-equivalent for implicits params)
回答2:
You can use ???
for undefined code parts (because it have bottom type Nothing
) and _
for unknown types. Also see -Ytyper-debug
compiler option (more options here: https://docs.scala-lang.org/overviews/compiler-options/index.html). According to problem with implicit parameters and wrappers, "Idea" has nice feature "Show Implicit Hints" and "Implicit Arguments" (Main menu > Help > Find Action...
and type e.g. implicit). Also, you can use Null
bottom type instance null
for AnyRef like null: YourTypeHere
.
来源:https://stackoverflow.com/questions/34753708/how-do-you-debug-typelevel-code