Skip to content

[Diagnostics] Treat type requirement failures associated with Self #26941

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 1 commit into from
Aug 30, 2019

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Aug 29, 2019

…= Any as unrelated

This helps us to filter out cases like operator overloads where
Self type comes from e.g. default for collection element -
[1, "hello"].map { $0 + 1 }. Main problem here is that
collection type couldn't be determined without unification to
Any and + failing for all numeric overloads is just a consequence.

…= `Any` as unrelated

This helps us to filter out cases like operator overloads where
`Self` type comes from e.g. default for collection element -
`[1, "hello"].map { $0 + 1 }`. Main problem here is that
collection type couldn't be determined without unification to
`Any` and `+` failing for all numeric overloads is just a consequence.
@xedin xedin requested a review from DougGregor August 29, 2019 22:29
@@ -182,8 +182,7 @@ func r22162441(_ lines: [String]) {

func testMap() {
let a = 42
[1,a].map { $0 + 1.0 } // expected-error {{binary operator '+' cannot be applied to operands of type 'Any' and 'Double'}}
// expected-note @-1 {{expected an argument list of type '(Double, Double)'}}
[1,a].map { $0 + 1.0 } // expected-error {{cannot convert value of type 'Int' to expected element type 'Double'}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still not quite right is it? The diagnostic talks about an 'element type' but that's Int here isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not really Int, since there is a literal which could be a Double as well, which would match + inside of the closure body.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see it from the perspective that if there was no a in there, everything would have type-checked correctly as [Double].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only other possible failure we could produce would say that $0 expected to be Double which might not be more useful since it still comes down to use of a.

@xedin
Copy link
Contributor Author

xedin commented Aug 30, 2019

@swift-ci please smoke test

@xedin
Copy link
Contributor Author

xedin commented Aug 30, 2019

If there are no objections I'm going to merge this pretty soon since it helps to make progress with other diagnostics.

@xedin xedin merged commit c16b888 into swiftlang:master Aug 30, 2019
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.

2 participants