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
- Read the found and required types in the message.
- Convert the value (parse, map, wrap) or fix the upstream type.
- Re-run
sbt compileto confirm the types align.
Sum.scala
def add = 1 + "3".toIntAlign 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
Scala sbt "could not find implicit value" in CIFix Scala "[error] could not find implicit value for parameter X" in CI - the compiler needed an implicit and…
Scala sbt "not found: value/object X" in CIFix Scala "[error] not found: value X" or "not found: object X" in CI - the compiler reached an identifier it…
Scala sbt "object X is not a member of package Y" in CIFix Scala "[error] object X is not a member of package Y" in CI - an import points at a package path that the…