Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any wart triggers false positive for higher kinded typeclass #463

Open
stankoua opened this issue Dec 23, 2019 · 5 comments
Open

Any wart triggers false positive for higher kinded typeclass #463

stankoua opened this issue Dec 23, 2019 · 5 comments

Comments

@stankoua
Copy link

I went through a warning with the following code snippet:

  trait One[F[_]] {}

  trait Two[F[_], A] {
    val arg: String
  }

  trait TypeClass1[F[_]] {
    def capability1: F[String]
  }

  object TypeClass1 {
    implicit val optionTC1: TypeClass1[Option] = new TypeClass1[Option] {
      def capability1: Option[String] = None
    }
  }

  def buildTwo[F[_]: TypeClass1](
      buildingArg: String
  ): Two[F, Two[F, One[F]]] =
    new Two[F, Two[F, One[F]]] {
      val arg: String = buildingArg
    }

  def myTwo: Two[Option, Two[Option, One[Option]]] =
    buildTwo("test")

During compilation, this warning is triggered:

[warn] Main.scala:35:5: [wartremover:Any] Inferred type containing Any: [+A]Option[A]
[warn]     buildTwo("test")
[warn]     ^
[warn] one warning found
[success] Total time: 1 s, completed 23 déc. 2019 23:01:31

I don't get this error when disabling the wartremoverWarnings ++= Warts.unsafe line in my build.sbt. I'm guessing I get this warning because the type parameter A of [+A]Option[A] is inferred to Any. Is there a way to avoid this warning without using suppressWarning annotation ?

@S11001001
Copy link

Almost certainly related to #455. @stankoua What scalac options are you using?

@stankoua
Copy link
Author

stankoua commented Jun 1, 2020

@S11001001 I was using scala 2.13 with following compiler options:

val compilerOptions = Seq(
  // Common settings
  //
  "-deprecation", // Emit warning and location for usages of deprecated APIs.
  "-encoding",
  "utf-8", // Specify character encoding used by source files.
  "-explaintypes", // Explain type errors in more detail.
  "-feature", // Emit warning and location for usages of features that should be imported explicitly.
  "-unchecked", // Enable additional warnings where generated code depends on assumptions.
  "-Xcheckinit", // Wrap field accessors to throw an exception on uninitialized access.
  "-Werror", // Fail the compilation if there are any warnings.
  "-Ymacro-annotations",
  // Warning settings
  //
  // "-Wself-implicit",
  "-Wdead-code",
  "-Wextra-implicit",
  "-Wnumeric-widen",
  "-Wvalue-discard",
  "-Wunused:imports,patvars,privates,locals,explicits,implicits,params,linted",
  // Linting
  //
  "-Xlint:adapted-args",
  "-Xlint:inaccessible", // Warn about inaccessible types in method signatures.
  "-Xlint:infer-any", // Warn when a type argument is inferred to be `Any`.
  "-Xlint:missing-interpolator",
  "-Xlint:doc-detached",
  "-Xlint:private-shadow",
  "-Xlint:type-parameter-shadow",
  "-Xlint:poly-implicit-overload",
  "-Xlint:option-implicit",
  "-Xlint:package-object-classes",
  "-Xlint:stars-align",
  "-Xlint:constant",
  "-Xlint:nonlocal-return",
  "-Xlint:valpattern",
  "-Xlint:eta-zero,eta-sam",
  "-Xlint:deprecation",
  "-Xlint:nullary-override", // Warn when non-nullary `def f()' overrides nullary `def f'.
  "-Xlint:nullary-unit", // Warn when nullary methods return Unit.
  "-Ywarn-value-discard" // Warn when non-Unit expression results are unused.
)

Just in case I configured Wartremover like this: wartremoverErrors ++= Warts.unsafe

@stankoua
Copy link
Author

stankoua commented Jun 1, 2020

Almost certainly related to #455. @stankoua What scalac options are you using?

Indeed I think the 2 issues are related. I have cats(+cats-effects) in my project and at first I got this error on a cats types (IO and Validated if I remember correctly). I tried to abstract it when creating the issue.

@Daenyth
Copy link
Contributor

Daenyth commented Jul 24, 2020

This triggers a lot on code invoking through on fs2.Stream

@solarmosaic-kflorence
Copy link

solarmosaic-kflorence commented Aug 13, 2021

Same for Slick: Inferred type containing Any: [+A]Seq[A]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants