Skip to content

FlexibleType's in the standard library artifact #23682

@sjrd

Description

@sjrd

We now build the entire standard library with explicit nulls enabled. While it is obviously good to have added internal guarantees, it also means that the published artifact comes from this compilation mode. This can lead to 2 things:

  1. Types of the form X | Null can appear where X was used before.
  2. FlexibleTypes can appear.

They can appear a) in APIs and b) in the TASTy body of methods.

Number 1. is no big deal, whether in public APIs or method bodies. When interpreted without explicit nulls, X | Null =:= X, so it does not make a difference.

FlexibleTypes are more problematic, as they are not, in fact, stable.

In APIs, this is of course a big issue. Fortunately, we can prevent that from happening by making sure to fully annotate the result types. That is considered good practice for public and protected methods; not always for vals. Ideally we would implement some automated check to make sure that we don't leak any FlexibleTypes in the APIs.

In the method bodies, the issue is less problematic. The compiler only looks at method bodies for inline methods. Here as well, ideally an automated check could make sure that no inline methods contains any FlexibleType.

Other tooling, besides the compiler, can definitely look at method bodies, though. For example, tasty-query has effectively had to fully support FlexibleTypes since they were introduced, even though they are not stable, because they often appear in method bodies. It is unclear to me how we can defend against that.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions