Skip to content
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

Test the nullness-augmented types of symbols in the classpath #99

Open
netdpb opened this issue Aug 18, 2023 · 1 comment
Open

Test the nullness-augmented types of symbols in the classpath #99

netdpb opened this issue Aug 18, 2023 · 1 comment
Assignees
Labels
conformance-tests Framework and implementation for conformance tests

Comments

@netdpb
Copy link
Collaborator

netdpb commented Aug 18, 2023

Given a class in the classpath, we need to assert that an analyzer can interpret the annotations on and surrounding each symbol correctly. For example, @NullMarked class Foo<T> { List<@Nullable T>bar(T arg) {…} } declares the following symbols:

  • Foo<T extends Object!>
  • List!<T?> Foo.bar(T)

Note that unlike the tests for expression types, sink types, conversion errors, and irrelevant annotations, these tests apply to analyzers' interpretaion of the spec with respect to compiled symbols and not Java source code. As such, these tests will apply to non-Java-source analyzers such as the Kotlin compiler.

@netdpb netdpb added the conformance-tests Framework and implementation for conformance tests label Aug 18, 2023
@netdpb netdpb self-assigned this Aug 18, 2023
@netdpb
Copy link
Collaborator Author

netdpb commented Aug 24, 2023

Here's an idea for representing the tests:

  1. Have Java source for the classes in a new directory in http://github.com/jspecify/jspecify, either within conformance or elsewhere.
  2. Some (maybe all?) nonprivate classes, fields, and methods in that directory will be annotated with a new class-retention annotation that has one string value, which contains that symbol's nullness-augmented type.
  3. Some (maybe all?) nonprivate classes in that directory will also be annotated with a new class-retention annotation that contains a list of inherited members and their nullness-augmented types, as well as supertypes and their nullness-augmented types.
  4. All those classes will be compiled into a JAR.
  5. That JAR will be passed to the checker, in conformance test mode.
  6. The checker will iterate through all the type elements in that JAR, and will emit nullness-augmented type information for every symbol (ignoring the test annotations above) and every inherited member and supertype.
  7. The test framework will compare that emitted data with the nullness-augmented type information it will read from the annotations in the JAR.

Example:

@TestType("Foo<T extends Object!>")
@TestSupertypes({"List<T extends Object!>", "Collection<T extends Object!>"})
@TestInheritedMembers({"T get()", "boolean add(T)"})
@NullMarked
abstract class Foo<T> implements List<T> {
  @TestType("String?(T?)")
  @Nullable String bar(@Nullable T t);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conformance-tests Framework and implementation for conformance tests
Projects
None yet
Development

No branches or pull requests

1 participant