Scala: missing parameter type for expanded function
The compiler reached a placeholder or a lambda before it knew the expected type, so there is nothing to infer the parameter from. The cause is inference order rather than the lambda itself: a value with no declared type, an overloaded method, or a chain whose receiver type is still being worked out.
Quick fix
Read the commands before running them. Anything that restarts a service, deletes data or changes permissions should be tried on a non-production system first.
// Nothing to infer from: there is no expected type here
// val f = _ + 1
// Say what the function is, either side of the equals sign
val f: Int => Int = _ + 1
val g = (x: Int) => x + 1
// In a chain, annotate the value that lost its type, not the lambda
val names: List[String] = load()
names.map(_.toUpperCase)
// Overloads defeat inference, so make the choice explicit
def handle(f: Int => Int): Unit = ()
def handle(f: String => String): Unit = ()
handle((s: String) => s.trim)
// Separate parameter lists let the first inform the second
def fold[A, B](xs: List[A])(z: B)(f: (B, A) => B): B = xs.foldLeft(z)(f)
fold(List(1, 2, 3))(0)(_ + _) // fine, B is known by the time f is typed
// Underscore inside a larger expression expands wider than people expect:
// xs.map(_ + 1) works, xs.map(f(_) + 1) often needs the parameter named
How to diagnose Scala errors
Scala's most distinctive error class is binary incompatibility: libraries are published per Scala major version, and mixing artifacts built for different versions produces confusing "not a member of" or NoSuchMethodError failures. The %% operator in sbt exists precisely to append the right suffix, and most unresolved-dependency errors are a % where %% was needed.
If the quick fix above does not resolve it, work through these steps. They apply to this whole class of error, not just to this one message, which is usually what saves the time.
- Check the Scala version suffix on every dependency. Use
%%for Scala libraries and plain%only for Java ones. - Run
sbt evictedto list dependencies that were evicted by version conflict. A frequent source of runtime NoSuchMethodError. - Use
sbt dependencyTreeto see the resolved graph and locate the transitive dependency pulling in an old version. - For inference failures, add explicit type annotations at the boundary rather than at the error site; inference failures usually propagate from further up.
- Clear stale state with
sbt cleanand remove~/.ivy2/cacheor~/.cache/coursierentries only for the specific failing artifact.
Tools worth reaching for
sbt evictedsbt dependencyTreecoursier resolvescalac -explainMiMa (binary compat checks)
Authoritative references
Primary documentation for this error, worth reading before applying any fix in production.
Related Scala errors
- sbt: Conflicting cross-version suffixes in: org.scala-lang.modulesTwo dependencies pulled in the same library built for different Scala versions, for example…
- sbt: found version conflict(s) in library dependenciesTwo dependencies need different versions of the same library, sbt picked the newer one, and…
- Scala 3: `_` is no longer supported for a type wildcard, use `?`Underscore is being reclaimed for type lambdas, so existing type wildcards have to be written…
- Scala 3: Ambiguous given instances: both X and Y match typeTwo givens of the same type are in scope with equal specificity, so the compiler refuses to…
- Scala 3: Implicit parameters should be provided with a `using` clauseFrom Scala 3.7 the compiler warns when you pass an argument to an implicit parameter list by…
- Scala 3: no given instance of type X was foundThe compiler needed a contextual value and could not find one in scope. This is Scala 3's…
- Scala module 2.15.2 requires Jackson Databind version >= 2.15.0 and < 2.16.0jackson-module-scala refuses to register unless jackson-databind on the classpath has the…
- Scala: could not find implicit value for parameterThe compiler could not supply an implicit argument, usually because the instance exists but…
Browse other categories
- HTTP 494xx client errors, 5xx server errors, redirects, headers and protocol problems.
- JavaScript 42npm resolution, async pitfalls, hydration, memory limits and runtime type…
- Database 41Connections, deadlocks, constraints, replication and memory limits.
- AI 35Rate limits, context windows, GPU memory and model-serving failures.
- Network 35Refused connections, timeouts, resets, MTU problems and port exhaustion.
- Python 35Imports, virtual environments, encoding, concurrency and dependency conflicts.
- Kubernetes 34CrashLoopBackOff, ImagePullBackOff, OOMKilled, RBAC, scheduling and storage.
- Docker 27Daemon connectivity, disk space, image pulls, ports and architecture mismatches.
- System 26Disk space, systemd units, file descriptors, OOM killer and scheduled jobs.
- Cloud 25IAM permissions, quotas, service limits and credential failures.
- Security 25JWT validation, CSRF, OAuth grants, SELinux, SSH host keys and CSP.
- TLS 24Untrusted authorities, expiry, hostname mismatch, chains and cipher negotiation.
Something missing or wrong?
This entry is maintained by hand. If the fix is out of date, incomplete, or you have a better one, email a correction and it will be reviewed.