According to the Scala Language Spec:
… local type inference is permitted to limit the complexity of inferred
bounds [of type parameters]. Minimality and maximality of types have to be understood
relative to the set of types of acceptable complexity.
In practice what are the limits?
Also, are there different limits that apply to inferred expression types than to parameter type bounds, and what are those limits?
When inferring types, the compiler often needs to calculate the Least Upper Bound (LUB) of a list of types. For example, the type of
if (cond) e1 else e1is the LUB of the types ofe1ande1.These types can get quite large, for example try this in a REPL:
This commit introduced some sanity checks to limit the depth of such inferred types.
There has been some recent work to plugin to the compilation process to detect inferred types that take a long time to calculate, and suggest places where an explicit type annotation might be prudent.