scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.85k stars 1.06k forks source link

Augment Nullability of known standard library signatures #7871

Open Katrix opened 4 years ago

Katrix commented 4 years ago

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.

abeln commented 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

vandmo commented 3 weeks ago

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.