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
[SR-5838] Can't infer type of inout parameter for an operator #48408
Comments
Comment by Howard Lovatt (JIRA) Looks like it could be a general problem with operators and generic type inference. Attached another example that gives a different error and doesn't use inout parameters. !st playground using inout is Operator..., 2nd without inout is Reference... |
The error messages need work, but the problem is that you shouldn't be making the function generic, because the context is already generic. You've shadowed the enclosing |
cc @xedin |
Comment by Howard Lovatt (JIRA) Thanks Jordan, that is definitely part of the problem. Deleting the extra T cures the 2nd example but the 1st example still fails. IE: class Box<T> {
} let b = Box("Test") var u: String? b >> &u // ERROR: Cannot convert value of type 'Box<String>' to expected argument type 'Box<_>' u Still fails with the same error message. |
Ah, interesting. Moreover,
actually works. I think this is fallout from our support for assignment operators where the |
To be clear, I would say assignment operators should only imply |
Comment by Howard Lovatt (JIRA) Thanks Jordan. I can use the workaround until fixed - actually in my use case it is better than having to put the & in since I am using the operator for assignment. As extra information - if I change to my actual operator - I used >> for simplicity in example - then the error message changes to "ambiguous expression type": infix operator ~~> : MultiplicationPrecedence class Box<T> {
} let b = Box("Test") var u: String? b ~~> &u // error: expression type '()' is ambiguous without more context u Thanks for the help. |
hlovatt (JIRA User) The problem here is that an argument of the |
Attachment: Download
Environment
MacOS 10.12.6
Xcode 9 beta 6
Additional Detail from JIRA
md5: e1f37be7e1af0d30689c36d19ce7d871
relates to:
Issue Description:
See attached playground.
The compiler can't infer the type of the argument to the operator.
Seems to only be a problem with inout parameters and operators.
The text was updated successfully, but these errors were encountered: