amnaredo / test

0 stars 0 forks source link

"Ambiguous implicit values" errors that make no sense #186

Open amnaredo opened 2 years ago

amnaredo commented 2 years ago

I am getting seemingly random error messages like

ambiguous implicit values:  both value derive$macro$121 of type => upickle.default.Writer[models.AdminFoodRecord]  and value derive$macro$137 of type => upickle.default.Writer[uk.ac.ncl.openlab.intake24.InheritableAttributes]  match expected type upickle.default.Writer[T1]
ambiguous implicit values:  both value derive$macro$190 of type => upickle.default.Writer[models.AdminFoodRecord]  and value derive$macro$206 of type => upickle.default.Writer[uk.ac.ncl.openlab.intake24.InheritableAttributes]  match expected type upickle.default.Writer[T1]
not enough arguments for method Tuple4W: (implicit evidence$13: upickle.default.Writer[T1], implicit evidence$14: upickle.default.Writer[T2], implicit evidence$15: upickle.default.Writer[T3], implicit evidence$16: upickle.default.Writer[T4])upickle.default.Writer[(T1, T2, T3, T4)]. Unspecified value parameters evidence$13, evidence$14, evidence$15...    
uPickle does not know how to write [T1]s; define an implicit Writer[T1] to teach it how

These are very confusing since the types that supposedly match the expected type are unrelated, so there is no way they can both match.

Also, this part: uPickle does not know how to write [T1]s; define an implicit Writer[T1] to teach it how -- T1 does not seem to be a real type, just a placeholder name.

How can I make sense of this? In particular, how can I tell what is the actual type of T1?

ID: 168 Original Author: mechkg

amnaredo commented 2 years ago

This is really driving me crazy...

The offending class' signature is as follows:

case class AdminFoodRecord(main: MainFoodRecord, local: LocalFoodRecord, brands: Seq[String], associatedFoods: Seq[UserAssociatedFood])

the following line produces the above error:

val t = write(record) // record is an instance of AdminFoodRecord

but none of the following lines produce any problems:

  val t1 = write(record.main)
  val t2 = write(record.local)
  val t3 = write(record.brands)
  val t4 = write(record.associatedFoods)

Now, if I add or remove a random field from AdminFoodRecord, the error goes away. It also goes away if I add or remove any field from UserAssociatedFood, which is

case class UserAssociatedFood (foodOrCategory: Either[UserFoodHeader, UserCategoryHeader], promptText: String, linkAsMain: Boolean, genericName: String)

so for instance if I do

case class UserAssociatedFood (foodOrCategory: Either[UserFoodHeader, UserCategoryHeader], promptText: String, linkAsMain: Boolean, genericName: String, test: String = "123")

the problem goes away.

But the error still occurs if

Now, the only thing in common between these two classes is that they both happen to have 4 fields, so I think this might be a problem with Tuple4W (which is generated and not any different from other case class lengths as far as I can see...), or else some obscure bug in the Scala compiler.

I tried inspecting the implicit resolution with -Xlog-implicits but that was an unreadable 800Kb mess...

Original Author: mechkg

amnaredo commented 2 years ago

+1. I have the same problem.

Original Author: danielyli

amnaredo commented 2 years ago

I run into this fairly often and I found a somewhat reliable solution on another issue somewhere (I think auto wire?) essentially the macros are being generated twice which is why they are ambiguous. Try specifying an implicit reader or writer such as

def doSomething(myClass : MyClass)(implicit writer : upickle.default.Writer[MyClass]) = { upickle.default.write(myClass) }.

Original Author: tannerezell

amnaredo commented 2 years ago

+1 Same problem here. And tannerezell's solution does not help.

Original Author: jk-1

amnaredo commented 2 years ago

I have the same problem. Is the problem with uPickle itself?

Okay:     case class CheckedInvoiceSet(invoices: Seq[InvoiceBar], adjustments: Seq[Adjustment],creditNotes: Seq[CreditNoteRow]) //ok
Fails:    case class CheckedInvoiceSet(invoices: Seq[InvoiceBar], adjustments: Seq[Adjustment],creditNotes: Seq[CreditNoteRow], latestCreditNoteNumbers: Int) // fails
Succeeds: case class CheckedInvoiceSet(invoices: Seq[InvoiceBar], adjustments: Seq[Adjustment],creditNotes: Seq[CreditNoteRow], latestCreditNote: CreditNoteRow) // succeeds

Original Author: aholland

amnaredo commented 2 years ago

@aholland Yes. It is definitely a bug. I could find no working workaround. Original Author: ebruchez

amnaredo commented 2 years ago

Sometimes you can fix this by simply removing the import:

import upickle.default._

and instead import only the specific parts you need. Original Author: tannerezell

amnaredo commented 2 years ago

Bug bankruptcy Original Author: lihaoyi

amnaredo commented 2 years ago

What does that mean?

On 19 December 2017 at 02:31, Li Haoyi notifications@github.com wrote:

Bug bankruptcy

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/lihaoyi/upickle/issues/168#issuecomment-352621356, or mute the thread https://github.com/notifications/unsubscribe-auth/AAx_-lVepvuGeYu-oltCSPr2iqco5my4ks5tByAYgaJpZM4Jax2B .

Original Author: mechkg

amnaredo commented 2 years ago

@mechkg it means Haoyi won't be fixing this bug as he is overwhelmed. I managed to combine Autowire with Circe instead of uPickle, here: https://github.com/aholland/autowire-circe

Original Author: aholland