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-3936] Provide a Fix It for errors such as "Computed property must have an explicit type" #46521
Comments
This diagnostic predates us putting editor placeholders in fix-its, but now that that's becoming more common it does make sense here. Tagging as a good starter bug. |
Comment by Elia Cereda (JIRA) If I understand correctly, what you're proposing is slightly different from what I had in mind. Let's say we start from this piece of code: class A {
static let shared = A()
}
class B {
var a { return A.shared }
} Are you proposing to fix-it to this? var a: <# Type #> { return A.shared } Wouldn't it be possible in this case to actually fix-it to this, since the getter already provides an indication of the type of the property? var a: A { return A.shared } |
Ah, that might work in simple cases. I was concerned about cases that rely on inferring something from context, i.e. the body of the getter might not be unambiguous. (It might also have multiple return statements, in which I'd rather not have the compiler try to pick a common type.) But in the case of a single return statement it might make sense to run the type-checker on the expression and see what type we'd get. |
Comment by Elia Cereda (JIRA) I'm trying to build Swift but I'm getting the following error almost immediately:
Maybe off-topic here, does this need a proper issue? |
Haven't seen that one before. Yeah, can you either file a separate bug or ask on swift-dev? |
Additional Detail from JIRA
md5: 9023757e88cd437914deadb3e6f97e38
Issue Description:
I think it would be nice to have a Fix It for this kind of errors, for example trying to infer the correct type from the body of the computed property. Since automatic inference isn't applied here, it would be useful to at least try applying it and make the inferred type available to the developer.
Personal example: I have written computed properties to alias properties on other objects, as a faster way to access them. I often don't know / I'm too lazy to remember the type of the property I'm aliasing, so I'd like the convenience of just writing the body of the computed property and have the compiler figure out the type for me.
I haven't searched yet for other errors where this might apply, nor I've looked at possible implementations. I'd like an indication on this part from someone with more experience on the compiler structure, but if this is something that's deemed nice to have I'd be happy to help in the implementation.
The text was updated successfully, but these errors were encountered: