Skip to content
Latchkey

Scala sbt "type mismatch; found ... required ..." in CI

scalac found an expression whose type does not match what the surrounding context requires, and no implicit conversion bridges them. It prints both the found and required types so you can see the gap.

What this error means

sbt compile fails with "[error] type mismatch; found : A required: B" under a caret pointing at the offending expression.

scala
[error] /src/main/scala/Sum.scala:4:14: type mismatch;
[error]  found   : String("3")
[error]  required: Int
[error]   def add = 1 + "3"
[error]                 ^

Common causes

The value is genuinely the wrong type

A String is passed where an Int is required, or an Option[A] where an A is expected, with no conversion in scope.

A signature changed in a dependency

An upgraded library changed a return or parameter type, so previously valid code now mismatches.

How to fix it

Convert or correct the expression

  1. Read the found and required types in the message.
  2. Convert the value (parse, map, wrap) or fix the upstream type.
  3. Re-run sbt compile to confirm the types align.
Sum.scala
def add = 1 + "3".toInt

Align with a changed dependency signature

When an upgrade changed a type, adapt the call site to the new signature rather than forcing a cast.

How to prevent it

  • Let the type checker guide conversions instead of casting.
  • Review type changes when upgrading libraries.
  • Compile locally so mismatches surface before CI.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →