This rewrite inserts type annotations for inferred public members.
- def myComplexMethod = 1.to(10).map(i => i -> i.toString).toMap + def myComplexMethod: Map[Int, String] = 1.to(10).map(i => i -> i.toString).toMap
By default, only rewrite adds type annotations for public members that have non-trivial bodies.
|Enable/disable this rule for defs, vals or vars.|
|Enable/disable this rule for private/protected members.|
|If false, insert explicit result types even for simple definitions like `val x = 2`|
|If false, insert explicit result types even for locally defined implicit vals|
|If true, report and fail unexpected errors. If false, silently ignore errors to produce an explicit result type.|
|If false, disables rewriting of inferred structural types to named subclasses. Beware that this option may produce code that no longer compiles if it previously used `scala.language.reflectiveCalls` to access methods on structural types.|
ExplicitResultTypes.memberKind = [ Def, Val, Var ] ExplicitResultTypes.memberVisibility = [ Public, Protected ] ExplicitResultTypes.skipSimpleDefinitions = ['Term.Ref', 'Lit', 'Term.New'] ExplicitResultTypes.skipLocalImplicits = true ExplicitResultTypes.fatalWarnings = false ExplicitResultTypes.rewriteStructuralTypesToNamedSubclass = true
ExplicitResultTypes.memberKind = [Def, Val, Var] ExplicitResultTypes.memberVisibility = [Public, Protected] ExplicitResultTypes.skipSimpleDefinitions = ['Lit', 'Term.New']
This rule has several known limitations, which are most likely fixable with some effort. At the time of this writing, there are no short-term plans to address these issues however.
Limited Scala support
Due to implementation details, this rule works only with 2.12.11. Scala 2.11 and 2.13 are not supported for this rule. See #988 if you want to contribute support for other Scala versions.
The rewrite inserts imports at the bottom of the global import list. Users are expected to organize the imports according to the conventions of their codebase.
For example, the rewrite may produce the following diff.
import java.io.File import scala.collection.mutable + import java.util.UUID
- use https://github.com/NeQuissimus/sort-imports.
- run "organize imports" refactoring in IntelliJ