Open Katrix opened 4 years ago
There are thousands of such methods/fields. This would be an important feature to have. In our prototype, we generated a list of standard library methods that should not return nullable values, using an annotated JDK taken from the Checker Framework.
The list is at https://github.com/abeln/dotty/blob/dotty-explicit-nulls-evaluation/explicit-nulls-meta.txt
But if we add this to the dotty repo we need a versioning story/way to track changes to the Java JDK.
cc @odersky @sjrd
This would be a killer feature for adopting -Yexplicit-nulls. I think that making it possible to narrow types in a separate library would be a good solution here. That would make it possible to fix the same issue when using other dependencies than just the Java standard library. I would also make it possible for the community to provide the type information. Python has https://github.com/python/typeshed and TypeScript has https://github.com/DefinitelyTyped/DefinitelyTyped wich are widely used.
This solution could be applied for other kinds of narrowing as well. For example, some methods that are returning Object today could probably be made to return a union type.
One such example is
Regex.Match#group
. I'm unsure if there are others, but would be great if the could get the correct type.