Skip to content
Latchkey

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.

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

  1. Read the "found" and "required" lines to see the exact gap.
  2. Convert the value (parse, map, wrap) so its type matches the requirement.
  3. Recompile to confirm the mismatch is gone.
Calc.scala
// found String, required Int
val total: Int = amount.toInt

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

App.scala
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.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →