Loosen compiler restriction which was not required by the spec#71110
Conversation
…aces when targeting IEnumerable<T>
|
@RikkiGibson ptal :) |
|
|
||
| var hasReadOnlyInterfaces = | ||
| !compilation.IsTypeMissing(SpecialType.System_Collections_Generic_IReadOnlyCollection_T) | ||
| && !compilation.IsTypeMissing(SpecialType.System_Collections_Generic_IReadOnlyList_T); |
There was a problem hiding this comment.
It feels like this should be initialized in terms of the contents of s_readOnlyInterfacesSpecialTypes, not repeating those types again here. We should also require the well-known Count and Length members to be present.
I think something like s_readOnlyInterfacesSpecialTypes.All(...IsPresent) && s_readOnlyInterfacesWellKnownMembers.All(...IsPresent) would be suitable.
There was a problem hiding this comment.
It's possible that I missed some reason that existence of the types should be checked here, but not existence of the members. @cston in case you had already given some advice here that I missed, I want to make sure we're in agreement about what to do for this.
There was a problem hiding this comment.
@RikkiGibson In an earlier form, it would implement the interfaces if present, and then implement each member if the member was present. Does that sound interesting?
There was a problem hiding this comment.
(Basically, the first commit in the branch)
There was a problem hiding this comment.
I think that would be fine, although I would suggest checking the members independently, we can simply implement the interfaces and members that happen to exist and don't implement the ones that don't exist.
(though if the well known interfaces have extra members that we didn't expect, it would also be reasonable to skip implementing the interface entirely or possibly to report an error. Is there already some precedent in this synthesized type already for this case?)
However, I don't want to lead you around in a circle if Cyrus or Chuck have already steered you away from that path. So let's make sure we have consensus on how that should work.
There was a problem hiding this comment.
i have zero opinion here. IT's up to compiler side how you'd like this code to be structured :)
There was a problem hiding this comment.
These are well-known interfaces with well-known members. Given that, I think we should handle the two likely cases - where the interfaces are available, and where the interfaces are not - to limit the test matrix today and in the future.
|
Yes, done now. |
|
Thanks @jnm2! |
|
Thanks for your guidance! |
|
Thanks @jnm2 ! |
| !compilation.IsTypeMissing(SpecialType.System_Collections_Generic_IReadOnlyCollection_T) | ||
| && !compilation.IsTypeMissing(SpecialType.System_Collections_Generic_IReadOnlyList_T); |
There was a problem hiding this comment.
compilation.IsTypeMissing
This helper doesn't seem to be actually checking if the type is missing. It's rather "IsTypeMarkedAsMissing" and therefore is not suitable for non-test code. The proper way to do this I think is to check if the return value is of type MissingMetadataTypeSymbol. Is that correct?
Closes #71054 /cc @CyrusNajmabadi