Skip to content

Augment Nullability of known standard library signatures #7871

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Katrix opened this issue Dec 30, 2019 · 2 comments
Open

Augment Nullability of known standard library signatures #7871

Katrix opened this issue Dec 30, 2019 · 2 comments

Comments

@Katrix
Copy link
Contributor

Katrix commented Dec 30, 2019

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
Copy link
Contributor

abeln commented Jan 10, 2020

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

@bishabosha bishabosha changed the title Give the correct type to methods in the Scala std library that can return null Augment Nullability of known standard library methods Nov 18, 2020
@bishabosha bishabosha changed the title Augment Nullability of known standard library methods Augment Nullability of known standard library signatures Nov 18, 2020
@vandmo
Copy link

vandmo commented Sep 27, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants