Scala "type mismatch; found ... required ..." in CI
The compiler expected type Y at this position but the expression produced type X, and there is no implicit conversion or subtype relationship to bridge them. Scala reports both the found and required types so you can align them.
What this error means
scalac fails with "type mismatch;" then two lines: "found : X" and "required: Y", pointing at the offending expression.
[error] /src/main/scala/Calc.scala:12:18: type mismatch;
[error] found : String
[error] required: Int
[error] total = amount
[error] ^Common causes
The expression genuinely has the wrong type
A value of one type is assigned or passed where another is required, with no conversion in scope.
An expected implicit conversion is not imported
Code that relies on an implicit conversion compiles elsewhere because the conversion is imported there; without that import the raw types do not match.
How to fix it
Convert or correct the value explicitly
- Read the "found" and "required" lines to see the exact gap.
- Convert the value (parse, map, wrap) so its type matches the requirement.
- Recompile to confirm the mismatch is gone.
// found String, required Int
val total: Int = amount.toIntBring the needed conversion into scope
If the code relies on an implicit conversion or typeclass instance, import it so the compiler can bridge the types.
import scala.jdk.CollectionConverters._How to prevent it
- Annotate public method return types so mismatches surface at the definition.
- Keep implicit imports explicit and local to where they are used.
- Enable a clean local compile before pushing to catch type errors early.