Remove most use of "Bogus" from Microsoft.CSharp and fix remaining#22537
Conversation
b27f6f1 to
ad797e1
Compare
| { | ||
| Name name; | ||
| bool isIndexer = property.GetIndexParameters() != null && property.GetIndexParameters().Length != 0; | ||
| bool isIndexer = property.GetIndexParameters().Length != 0 |
There was a problem hiding this comment.
Any reason to use predicateless-Any() on an array? The perf difference isn't much, but it's there, and Length != 0 is common with arrays elsewhere in corefx.
There was a problem hiding this comment.
I think Length is ok when we know it is an array. "Any" is often faster with various kind of collections/enumerables, but for array we know the "Length != 0" is the simplest way to check for emptiness.
In reply to: 129472003 [](ancestors = 129472003)
| Name name; | ||
| bool isIndexer = property.GetIndexParameters() != null && property.GetIndexParameters().Length != 0; | ||
| bool isIndexer = property.GetIndexParameters().Length != 0 | ||
| && (property.DeclaringType?.GetCustomAttribute(typeof(DefaultMemberAttribute)) as DefaultMemberAttribute) |
There was a problem hiding this comment.
DefaultMemberAttribute [](start = 83, length = 22)
GetCustomAttribute()?
There was a problem hiding this comment.
Sorry, I don't understand this comment.
There was a problem hiding this comment.
Oh. TIL about the generic GetCustomAttribute<>() extension!
| @@ -288,46 +288,7 @@ typeThru is NullableType || | |||
|
|
|||
| public bool CheckBogus(Symbol sym) | |||
There was a problem hiding this comment.
Please use this everywhere this functionality is needed. Example: GroupToArgsBinder.LookForCandidates()
There was a problem hiding this comment.
Done. Have also made it static as it requires no state.
| return (IndexerSymbol)this; | ||
| } | ||
|
|
||
| public bool Bogus { get; set; } |
There was a problem hiding this comment.
I suggest keeping with other fields, or converting all fields to properties.
I know there is a bigger effort of refactoring these things, but we shouldn't special case this here now.
There was a problem hiding this comment.
isIndexer and AsIndexerSymbol should ideally have been changed when getting rid of the similar methods defined elsewhere, anyway.
| } | ||
|
|
||
| [Fact] | ||
| public void LiteralDoubleCast() |
There was a problem hiding this comment.
Not sure how this relates to this PR. Maybe from #22533?
There was a problem hiding this comment.
Yeah, something slipped while doing a bunch of rebases. Sorry.
Since bogus types can't get as far as the dynamic binder, the only case where bogus can be true is when a non-indexer parametrized property, defined in a language where that is allowed, is encountered. In other cases computing bogosity involves recursive checks that always hit false. Give PropertySymbol a separate Bogus property to use where it could be set, and remove all other uses of GetBogus and similar. Entails removal of ERR_BogusType, contributes to #22470
AddPropertyToSymbolTable assumes any property with parameters is an indexer, which makes the subsequent check that only indexers can have parameters tautologous. Check DefaultMemberAttribute instead.
useMethInstead should be set in AddPropertyToSymbolTable when bogus is set, but is not. However, the only time it is looked for the only possible value is true as that is the only condition under which a symbol can be bogus, so remove it, and the path for it being false. This now means that ErrorCode.ERR_BindToBogusProp1 or ErrorCode.ERR_BindToBogusProp2 will be used when appropriate. Fixes #22534
Predefined properties cannot be bogus.
ad797e1 to
680e0ff
Compare
| public bool isOverride; // Overrides an inherited member. Only valid if isVirtual is set. | ||
| // false implies that a new vtable slot is required for this method. | ||
| public bool useMethInstead; // Only valid iff isBogus == TRUE && IsPropertySymbol(). | ||
| // If this is true then tell the user to call the accessors directly. |
There was a problem hiding this comment.
This comment refers to the code that is now gone. Also the comment above looks like after the code it is referring to. Can that be fixed too?
a4773d5 to
ca232cb
Compare
…otnet/corefx#22537) * Remove concept of bogus from types and most symbols. Since bogus types can't get as far as the dynamic binder, the only case where bogus can be true is when a non-indexer parametrized property, defined in a language where that is allowed, is encountered. In other cases computing bogosity involves recursive checks that always hit false. Give PropertySymbol a separate Bogus property to use where it could be set, and remove all other uses of GetBogus and similar. Entails removal of ERR_BogusType, contributes to dotnet/corefx#22470 * Identify indexer properties correctly in AddPropertyToSymbolTable AddPropertyToSymbolTable assumes any property with parameters is an indexer, which makes the subsequent check that only indexers can have parameters tautologous. Check DefaultMemberAttribute instead. * Remove useMethInstead from property symbols and consider always true. useMethInstead should be set in AddPropertyToSymbolTable when bogus is set, but is not. However, the only time it is looked for the only possible value is true as that is the only condition under which a symbol can be bogus, so remove it, and the path for it being false. This now means that ErrorCode.ERR_BindToBogusProp1 or ErrorCode.ERR_BindToBogusProp2 will be used when appropriate. Fixes dotnet/corefx#22534 * Tests for accessing non-indexer parameter properties * Remove bogus check within PredefinedMembers Predefined properties cannot be bogus. * Refactor CheckBogus to static and use consistently. * Replace IsIndexer and AsIndexer with direct operations * Make all fields in PropertySymbol auto properties. * Use generic form of GetCustomAttribute in looking up default member. * Remove confusing leftover remnant of comment. Commit migrated from dotnet/corefx@a2b8a66
Since bogus types can't get as far as the dynamic binder, the only case where bogus can be true is when a non-indexer parametrized property, defined in a language where that is allowed, is encountered.
In other cases computing bogosity involves recursive checks that always hit false.
Give
PropertySymbola separateBogusproperty to use where it could be set, and remove all other uses ofGetBogusand similar.Entails removal of
ERR_BogusType, contributes to #22470AddPropertyToSymbolTableAddPropertyToSymbolTableassumes any property with parameters is an indexer, which makes the subsequent check that only indexers can have parameters tautologous.Check
DefaultMemberAttributeinstead.useMethInsteadfrom property symbols and consider always true.useMethInsteadshould be set inAddPropertyToSymbolTablewhen bogus is set, but is not.However, the only time it is looked for the only possible value is true as that is the only condition under which a symbol can be bogus, so remove it, and the path for it being false.
This now means that
ErrorCode.ERR_BindToBogusProp1orErrorCode.ERR_BindToBogusProp2will be used when appropriate (contributes to #22470).Fixes #22534
Tests for accessing non-indexer parameter properties
Remove bogus check within PredefinedMembers
Predefined properties cannot be bogus.