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-10979] Add FixIt for "Operator implementation without matching operator declaration" #53368
Comments
Comment by Zsolt Török (JIRA) I really would like to tackle this down, as my first contribution. Could someone help me a bit? I think I found how to add the Fix-It, but I'm not quite sure how to position the inserted snippets. I may also have some question about testing. |
Comment by Michal Cichecki (JIRA) Where exactly do we want to put these error messages? I was thinking about adding it to the line before function declaration: infix operator <=> : <# Precedence Group #>
func <=> (lhs: Int, rhs: Int) -> Bool { false } and <# prefix or postfix #> operator <=> : <# Precedence Group #>
prefix func <=>(lhs: X) -> X {} |
Comment by Zsolt Török (JIRA) mcichecki (JIRA User) class C {
static func <=> (lhs: C, rhs: C) -> Bool { false }
} In this case, I think, we need to add the FixIt to the line before the class declaration instead of the line before the function declaration. Furthermore, I suppose, we need to think about nested classes too. |
Comment by Michal Cichecki (JIRA) torokzsolt (JIRA User) in this case we should also include extensions. This is example from docs.swift.org: infix operator +-: AdditionPrecedence
extension Vector2D {
static func +- (left: Vector2D, right: Vector2D) -> Vector2D {
return Vector2D(x: left.x + right.x, y: left.y - right.y)
}
} The only question is if that's really something that we should take care of or leave it to user who will change the position after the operator is added according to his need. |
Comment by Zsolt Török (JIRA) mcichecki (JIRA User) You are absolutely right. |
Comment by Michal Cichecki (JIRA) |
This got merged, so feel free to mark it Resolved, mcichecki (JIRA User). :-) Thank you for the fix! |
Additional Detail from JIRA
md5: f0bd648bfcc55e26a41a74cccf434f09
Issue Description:
If you create an operator function without declaring the operator, like so:
You get an error:
It would be nice to have a Fix-It for this, that puts a regular operator there.
If the function body has 2 parameters, you could supply
And if there's one parameter, you could supply
The text was updated successfully, but these errors were encountered: