Scalafix semantic rule that flags Scala 3 call sites which can trigger slow type inference when:
- a method omits a type argument,
- that type argument is higher-kinded (for example
F[_]), - that type argument affects the result type, but not as the top-level result constructor itself (for example
Resource[F, Unit]is checked,F[Int]is not), - it only shows up through implicit / context evidence,
- and the result is immediately chained on, including
forgenerators.
This rule is a workaround for the Scala 3 compiler issue scala/scala3#18763.
Add the rule to your build:
ThisBuild / scalafixDependencies +=
"org.polyvariant" %% "SlowInferenceChain" % versionThen run Scalafix on your sources:
sbt "scalafix SlowInferenceChain"or add it to your .scalafix.conf:
rules = [
DisableSyntax,
LeakingImplicitClassVal,
NoAutoTupling,
NoValInForComprehension,
RedundantSyntax,
+ SlowInferenceChain,
]
rules/— the rule implementationinput/— test fixtures consumed by Scalafix testkitoutput/— unused for this linter, kept for the standard testkit layouttests/— the Scalafix test suite
sbt rules/compile
sbt tests/testPositive cases:
- chained method call on the inferred result
for-comprehension generator
Negative cases:
- explicit type argument already present
- plain type parameter rather than a higher-kinded one
- no chaining after the call
- type parameter appears in a non-implicit parameter
- no implicit / given evidence for the type parameter
- matching higher-kinded type parameter and corresponding implicit evidence already exist in an enclosing scope
- return type does not depend on the inferred type parameter
- return type is directly
F[...]