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.

shapeless.Coproduct is imported but not used

See original GitHub issue

Generated code that uses Shapeless Coproduct includes this import:

import shapeless.{:+:, CNil, Coproduct}

Example.

However, it seems that the generated code doesn’t actually use shapeless.Coproduct, which causes the following compiler error (I think if you have both -Xfatal-warnings and -Ywarn-unused:imports):

[error] /Users/foo/bar/target/scala-2.12/src_managed/test/compiled_avro/com/foo/Bar.scala:4: Unused import
[error] import shapeless.{:+:, CNil, Coproduct}
[error]                              ^
[error] one error found

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
zcoxcommented, Mar 19, 2018

shapeless.Coproduct is used in the generated Scala file for default values.

    record RecordWithADefaultValue {
        union { int, string, boolean } isb = 0;
    }
case class RecordWithADefaultValue(isb: Int :+: String :+: Boolean :+: CNil = Coproduct[Int :+: String :+: Boolean :+: CNil](0))

It would be great if the shapeless.Coproduct import could just be omitted when it is not used in the generated Scala.

0reactions
rkorvercommented, Apr 6, 2022

Hi @julianpeeters

When using a union of more than 2 types, using sbt compile, (plugin version 2.0.0), I’m getting this “unused import” error in the parent generated class.

https://stackoverflow.com/questions/41478202/can-we-use-oneof-in-confluent-platform-schema-registry (the schema in the response works – also with 3 types in the union.)

The schema below doesn’t work, even though the avro schema is/seems valid:

{
 "name": "userBalance",
 "type": "record",
 "fields": [
   {
     "name": "currentBalance",
     "type": {
       "type": "record",
       "name": "CurrentBalance",
       "fields": [
         {
           "name": "userBalance",
           "type": [
             {
               "type": "record",
               "name": "userCashDeposit",
               "fields": [
                 {
                   "name": "id",
                   "type": "long"
                 },
                 {
                   "name": "amount",
                   "type": "float"
                 }
               ]
             },
             {
               "type": "record",
               "name": "userCashWithdraw",
               "fields": [
                 {
                   "name": "id",
                   "type": "long"
                 },
                 {
                   "name": "amount",
                   "type": "float"
                 }
               ]
             },
             {
               "type": "record",
               "name": "userBalanceCheck",
               "fields": [
                 {
                   "name": "id",
                   "type": "long"
                 },
                 {
                   "name": "amount",
                   "type": "float"
                 }
               ]
             }
           ]
         }
       ]
     }
   }
 ]
}

Yielding:

my_path/userBalance.scala:2:24: Unused import
[error] import shapeless.{:+:, CNil}

I’m probably missing something here… but if it’s a bug, might you have a fix / workaround for this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Coproducts in shapeless does not compile - Stack Overflow
I think you're looking for Inject : import shapeless._ import shapeless.ops.coproduct.Inject // for converter object import ...
Read more >
Shapeless Coproducts | Toby Hobson
A type safe, composable alternative to sealed trait hierarchies.
Read more >
milessabin/shapeless - Gitter
Hi. I've been playing with no-inheritance type modelling, with leaf types and using shapeless coproducts where I would otherwise have used a parent...
Read more >
Type-safe error handling with Shapeless coproducts in Scala
Conclusion. We have looked at Shapeless coproducts and saw that it is a union type (e.g. it can return more than a single...
Read more >
shapeless/ops/coproduct.scala - xuwei-k.github.com
See the License for the specific language governing permissions and * limitations under the License. */ package shapeless package ops import poly.
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