Skip to content

Sema: Fancier handling of associated type defaults #70241

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

Merged
merged 3 commits into from
Dec 7, 2023

Conversation

slavapestov
Copy link
Contributor

Consider this code:

protocol P {
  associatedtype A
  ...
}

protocol Q: P {
  associatedtype A = Int
  ...
}

struct S: Q {
  ...
}

If we check the [S: Q] conformance first, we get the right type witness
assignment, but if we check [S: P] first, conformance checking fails.

Instead of looking at an associated type declaration and any associated
types that it overrides, we now look through all associated types with the
same name among the protocols the adoptee conforms to. This allows us to
find the default assignment 'A = Int' from Q regardless of request
evaluation order.

Fixes rdar://problem/119052782.

@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

Consider this code:

    protocol P {
      associatedtype A
      ...
    }

    protocol Q: P {
      associatedtype A = Int
      ...
    }

    struct S: Q {
      ...
    }

If we check the [S: Q] conformance first, we get the right type witness
assignment, but if we check [S: P] first, conformance checking fails.

Instead of looking at an associated type declaration and any associated
types that it overrides, we now look through all associated types with the
same name among the protocols the adoptee conforms to. This allows us to
find the default assignment 'A = Int' from Q regardless of request
evaluation order.

Fixes rdar://problem/119052782.
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor Author

Not running source compat again -- the latest force-push just fixes a validation test

@slavapestov slavapestov merged commit 3372103 into swiftlang:main Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant