Skip to content

[SR-8239][Parse] Fix same-type constraint commutativity #19233

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

Conversation

AnthonyLatsis
Copy link
Collaborator

Same-type constraints are not always commutative, i.e. (see SR for more)

protocol P { associatedtype Assoc }
func foo<U, T: P>(...) where T.Assoc == U? { }  // ok

func foo<U, T: P>(...) where U? == T.Assoc { }  // 4 parsing errors

Resolves SR-8239.

@AnthonyLatsis
Copy link
Collaborator Author

cc @slavapestov

@rintaro
Copy link
Member

rintaro commented Sep 10, 2018

Could you add test case for : requirement? For example where [T]: Equatable, where T & Collection: Sequence

@AnthonyLatsis AnthonyLatsis force-pushed the same-type-constr-commutativity branch from 5906565 to 11616ff Compare September 11, 2018 00:24
@slavapestov
Copy link
Contributor

Looks good! As @rintaro mentioned it would be good to ensure that invalid cases that can now parsed are correctly rejected without crashing.

@AnthonyLatsis AnthonyLatsis force-pushed the same-type-constr-commutativity branch 2 times, most recently from 5db3c6e to 2f867a1 Compare September 11, 2018 01:24
@slavapestov
Copy link
Contributor

@swift-ci Please smoke test

@AnthonyLatsis
Copy link
Collaborator Author

AnthonyLatsis commented Sep 11, 2018

I think it makes sense to leave the error message as "expected type".

@AnthonyLatsis AnthonyLatsis force-pushed the same-type-constr-commutativity branch from 2f867a1 to e78a42b Compare September 11, 2018 02:18
@slavapestov
Copy link
Contributor

@swift-ci Please smoke test

@slavapestov slavapestov self-assigned this Sep 11, 2018
@slavapestov slavapestov merged commit 3d7b7bd into swiftlang:master Sep 11, 2018
@AnthonyLatsis
Copy link
Collaborator Author

Thank you for reviewing!

@AnthonyLatsis AnthonyLatsis deleted the same-type-constr-commutativity branch February 17, 2022 21:04
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.

3 participants