Reliable and powerful type inference in a language like Scala is crucial to providing a good developer experience. This has been on our mind while developing Dotty and as a result we’ve tried pretty hard to keep inferring things that Scala 2 is able to infer while at the same time simplifying and generalizing the type inference rules so that we may infer more things (there is no written documentation on this yet, but I have an old talk where I go into details: video slides)
However, it’s pretty hard to find examples of code that should infer but doesn’t, this is why I’d like to use this thread to ask for code samples where you feel that type inference should be able to do a better job. If possible:
- Try keeping the code as simple and small as possible
- Avoid relying on external dependencies
- Avoid depending on macros (e.g., replace macros by dummy code with the same signature, protip: you can pass
-Xprint:typerto scalac to see what your code looks like after typechecking and macro expansion, and you can also pass
-Xprint-typesto see the type of every tree node).
But I’ll accept any kind of code that I can run. My preferred delivery format would be a link to a page on https://scastie.scala-lang.org/ (you can add all the dependencies you want in the “Build Settings” page).
Feel free to also explain why you think that inference should work in this particular case!
Thank you for participating!