You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
protocolP {
letx : Int// error: immutable property requirement must be declared as 'var' with a '{ get }' specifier
}
This diagnostic is not quite accurate. There is 1 of 2 things the user is trying to do:
1. They really want an immutable property. This is impossible given current restrictions, because `let` implies that the property is a stored property (it is not possible today to determine if the computation is pure, if computed `let` properties were to be allowed) and protocols cannot enforce whether the witnesses are stored or computed.
2. They want a read-only property. This can be solved with `var { get }`.
The diagnostic is saying that if you want to get 1., use the solution for 2., which is not quite right. Instead, we should be clearer about potential things they want and what the solutions are. At the very least, mixing those two things up doesn’t feel right.
We should change the diagnostic to something like:
protocolP {
letx : Int// protocols cannot require properties to be immutable; declare read-only properties by using 'var' with a '{ get }' specifier
}
You can grep the codebase to find where the error text is and then replace it with the suggested text (or if you have a better idea, feel free to suggest that 🙂).
Please make sure that you update any test cases or add one if we are missing a test case for this diagnostic.
You can @ me (varungandhi-apple) on GitHub for review.
The text was updated successfully, but these errors were encountered:
Hmm, I think the reason why the diagnostic is worded in that way is because the user can still implement it as a let which makes it immutable and which is what I believe most of them would do with a var foo: Type {get} requirement anyway. So, I think it might be worth keeping that in mind when changing the diagnostic wording.
Yeah, I don't think this diagnostic specifically is the right place for that (because the diagnostic is about the protocol requirement, not the witness), but if we are adding extra informative notes, we can add the information about different potential witnesses.
Additional Detail from JIRA
md5: 5490ca2514b7d3781b548e117ac40d68
Issue Description:
If you write some code like
This diagnostic is not quite accurate. There is 1 of 2 things the user is trying to do:
1. They really want an immutable property. This is impossible given current restrictions, because `let` implies that the property is a stored property (it is not possible today to determine if the computation is pure, if computed `let` properties were to be allowed) and protocols cannot enforce whether the witnesses are stored or computed.
2. They want a read-only property. This can be solved with `var { get }`.
The diagnostic is saying that if you want to get 1., use the solution for 2., which is not quite right. Instead, we should be clearer about potential things they want and what the solutions are. At the very least, mixing those two things up doesn’t feel right.
We should change the diagnostic to something like:
You can grep the codebase to find where the error text is and then replace it with the suggested text (or if you have a better idea, feel free to suggest that 🙂).
Please make sure that you update any test cases or add one if we are missing a test case for this diagnostic.
You can @ me (varungandhi-apple) on GitHub for review.
The text was updated successfully, but these errors were encountered: