Skip to content

[record_use] Completeness: Support non-redirecting factories in static call recording #3192

@dcharkes

Description

@dcharkes

For v1: We should disallow record use annotations on factories and constructors.

When recording instances we take into account generative constructors and redirecting factories and tearoffs to those. We know what kind of instances they produce.

Non-redirecting factories are not treated explicitly. Their bodies may contain a call to a generative constructor, and such call is recorded as if it were a call to a generative constructor anywhere in the code. So, for instance recording this is correct.

However, such factories are not much different from static methods, so we could consider allowing recording them in the same way as static methods.

They are slightly more challenging though, because they might have redirecting factories pointing at them.

I don't believe we have any use cases right now, so marking this as low prio.

A list of tests to add if we do:

  1. Class Ordinary Factories
  • Direct Call: Annotated ordinary factory in a class, called with constant and non-constant arguments.
  • Tear-off: Tear-off of an annotated ordinary factory in a class.
  • Redirecting Call: Redirecting factory pointing to an annotated ordinary factory in a class.
  • Redirecting Tear-off: Tear-off of a redirecting factory pointing to an annotated ordinary factory in a class.
  1. Enum Ordinary Factories
  • Direct Call: Annotated ordinary factory in an enum, called with constant arguments.
  • Tear-off: Tear-off of an annotated ordinary factory in an enum.
  • Redirecting Call: Redirecting factory pointing to an annotated ordinary factory in an enum.
  • Redirecting Tear-off: Tear-off of a redirecting factory pointing to an annotated ordinary factory in an enum.
  1. Extension Type Ordinary Factories
  • Direct Call: Annotated ordinary factory in an extension type, called with constant arguments.
  • Tear-off: Tear-off of an annotated ordinary factory in an extension type.
  • Redirecting Call: Redirecting factory pointing to an annotated ordinary factory in an extension type.
  • Redirecting Tear-off: Tear-off of a redirecting factory pointing to an annotated ordinary factory in an extension type.
  1. Edge Cases & Deep Redirections
  • Deep Redirection: Redirecting factory A -> Redirecting factory B -> Annotated Ordinary Factory.
  • Redundant Annotation: Annotated ordinary factory inside an already annotated @RecordUse class.
  • Optional Arguments: Annotated ordinary factory with optional/named parameters to ensure full argument capture.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4A feature or bug we're unlikely to addresspackage:record_use

    Type

    No type

    Projects

    Status

    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions