Skip to content

API Compat doesn't validate changes to structs that would break compat #43628

Open
@ericstj

Description

@ericstj

Describe the bug

Today we synthesize private fields to structs to ensure that when omitting their internal/private API we don't break the following rules:

// SynthesizeDummyFields yields private fields for the namedType, because they can be part of the API contract.
// - A struct containing a field that is a reference type cannot be used as a reference.
// - A struct containing nonempty fields needs to be fully initialized. (See "definite assignment" rules)
// "non-empty" means either unmanaged types like ints and enums, or reference types that are not the root.
// - A struct containing generic fields cannot have struct layout cycles.

We should add rules to API compat to validate that such changes don't occur to a struct.

  1. Adding a reference type field to a struct that didn't previously have a reference type field.
  2. Adding non-empty fields to a struct that didn't previously have non-empty fields.
  3. Adding fields to a struct that use a generic type when it previously did not have fields that used the generic type.

To Reproduce

Omit all the _dummy* fields from the reference source in runtime.
Build.

Expect: API Compat emits diagnostics for all the missing fields.
Actual: No diagnostics.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions