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.
[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.
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.