-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Loosen compiler restriction which was not required by the spec #71110
Conversation
…aces when targeting IEnumerable<T>
...rs/CSharp/Portable/Symbols/Synthesized/ReadOnlyListType/SynthesizedReadOnlyListTypeSymbol.cs
Outdated
Show resolved
Hide resolved
...rs/CSharp/Portable/Symbols/Synthesized/ReadOnlyListType/SynthesizedReadOnlyListTypeSymbol.cs
Show resolved
Hide resolved
...rs/CSharp/Portable/Symbols/Synthesized/ReadOnlyListType/SynthesizedReadOnlyListTypeSymbol.cs
Outdated
Show resolved
Hide resolved
...rs/CSharp/Portable/Symbols/Synthesized/ReadOnlyListType/SynthesizedReadOnlyListTypeSymbol.cs
Outdated
Show resolved
Hide resolved
...rs/CSharp/Portable/Symbols/Synthesized/ReadOnlyListType/SynthesizedReadOnlyListTypeSymbol.cs
Show resolved
Hide resolved
@RikkiGibson ptal :) |
...rs/CSharp/Portable/Symbols/Synthesized/ReadOnlyListType/SynthesizedReadOnlyListTypeSymbol.cs
Outdated
Show resolved
Hide resolved
@@ -89,6 +101,10 @@ internal static NamedTypeSymbol Create(SourceModuleSymbol containingModule, stri | |||
var compilation = containingModule.DeclaringCompilation; | |||
DiagnosticInfo? diagnosticInfo = null; | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Basically, the first commit in the branch)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Closes #71054 /cc @CyrusNajmabadi