sbt "type mismatch; found X required Y" in CI
scalac expected one type and got another. The expression on the line produced a value whose type does not conform to where it is used, so compilation stops.
What this error means
The build fails with type mismatch; found : X required: Y, pointing a caret at the offending expression. It is fully deterministic and reproduces on every compile.
[error] /src/main/scala/App.scala:14:20: type mismatch;
[error] found : String
[error] required: Int
[error] val total: Int = config("retries")
[error] ^
[error] one error foundCommon causes
A value of the wrong type is supplied
The right-hand side or argument is genuinely the wrong type. A String is handed where an Int is required, or an Option where the bare value is expected.
A missing implicit conversion or type class
The code relies on an implicit that is not in scope, so the compiler refuses to bridge the two types and reports the mismatch.
Inference widened the type
Inference settled on a common supertype (often Any or AnyVal) for a conditional or collection, which then fails to satisfy a more specific required type.
How to fix it
Produce the required type explicitly
Convert or correct the expression so its type matches what the position requires.
val total: Int = config("retries").trim.toIntBring the needed implicit into scope
- Identify which type class or conversion the call needs.
- Import it, or add it as an implicit parameter.
- Prefer explicit conversions over hidden implicit magic in core logic.
Annotate to steer inference
Add an explicit type annotation to the binding or branches so inference does not widen to an unexpected supertype.
How to prevent it
- Annotate public method return types.
- Compile locally so type errors surface before CI.
- Avoid relying on implicit conversions for core data flow.