-
Notifications
You must be signed in to change notification settings - Fork 847
Open Static Classes - Updates #7405
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
Closed
TIHan
wants to merge
8
commits into
dotnet:master
from
TIHan:feature/open-static-classes-preview-flag1
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a9261cc
Open static classes is now preview. Added fix for overloads
TIHan dbf1bf6
Fixing tests
TIHan 9efac53
Fixed opening multiple times
TIHan 43d47f7
Shadow methods
TIHan ab0916f
few fixes
TIHan 1114ce9
Merge branch 'release/dev16.3' into feature/open-static-classes-previ…
TIHan 04cfcb4
Added events
TIHan cf999d9
Merge branch 'master' into feature/open-static-classes-preview-flag1
cartermp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -775,36 +775,108 @@ let AddStaticContentOfTyconRefToNameEnv (g:TcGlobals) (amap: Import.ImportMap) a | |
| if amap.g.langVersion.SupportsFeature LanguageFeature.OpenStaticClasses then | ||
| let ty = generalizedTyconRef tcref | ||
| let infoReader = InfoReader(g,amap) | ||
| let items = | ||
| [| let methGroups = | ||
| AllMethInfosOfTypeInScope ResultCollectionSettings.AllResults infoReader nenv None ad PreferOverrides m ty | ||
| |> List.groupBy (fun m -> m.LogicalName) | ||
|
|
||
| for (methName, methGroup) in methGroups do | ||
| let methGroup = methGroup |> List.filter (fun m -> not m.IsInstance && not m.IsClassConstructor) | ||
| if not methGroup.IsEmpty then | ||
| yield KeyValuePair(methName, Item.MethodGroup(methName, methGroup, None)) | ||
|
|
||
| let propInfos = | ||
| AllPropInfosOfTypeInScope ResultCollectionSettings.AllResults infoReader nenv None ad PreferOverrides m ty | ||
| |> List.groupBy (fun m -> m.PropertyName) | ||
|
|
||
| for (propName, propInfos) in propInfos do | ||
| let propInfos = propInfos |> List.filter (fun m -> m.IsStatic) | ||
| for propInfo in propInfos do | ||
| yield KeyValuePair(propName , Item.Property(propName,[propInfo])) | ||
|
|
||
| let getMethItems () = | ||
| [ let methGroups = | ||
| AllMethInfosOfTypeInScope ResultCollectionSettings.AllResults infoReader nenv None AccessorDomain.AccessibleFromSomeFSharpCode PreferOverrides m ty | ||
| |> List.groupBy (fun m -> m.LogicalName) | ||
|
|
||
| for (methName, methGroup) in methGroups do | ||
| let methGroup = methGroup |> List.filter (fun m -> not m.IsInstance && not m.IsClassConstructor) | ||
| if not methGroup.IsEmpty then | ||
| yield KeyValuePair(methName, Item.MethodGroup(methName, methGroup, None)) | ||
| ] | ||
|
|
||
| let getPropItems () = | ||
| [ let propInfos = | ||
| AllPropInfosOfTypeInScope ResultCollectionSettings.AllResults infoReader nenv None AccessorDomain.AccessibleFromSomeFSharpCode PreferOverrides m ty | ||
| |> List.groupBy (fun m -> m.PropertyName) | ||
|
|
||
| let fields = | ||
| for (propName, propInfos) in propInfos do | ||
| let propInfos = propInfos |> List.filter (fun m -> m.IsStatic) | ||
| for propInfo in propInfos do | ||
| yield KeyValuePair(propName , Item.Property(propName,[propInfo])) | ||
| ] | ||
|
|
||
| let getFieldItems () = | ||
| [ let fields = | ||
| infoReader.GetILFieldInfosOfType(None, ad, m, ty) | ||
| |> List.groupBy (fun f -> f.FieldName) | ||
|
|
||
| for (fieldName, fieldInfos) in fields do | ||
| let fieldInfos = fieldInfos |> List.filter (fun fi -> fi.IsStatic) | ||
| for fieldInfo in fieldInfos do | ||
| yield KeyValuePair(fieldName, Item.ILField(fieldInfo)) | ||
| |] | ||
| for (fieldName, fieldInfos) in fields do | ||
| let fieldInfos = fieldInfos |> List.filter (fun fi -> fi.IsStatic) | ||
| for fieldInfo in fieldInfos do | ||
| yield KeyValuePair(fieldName, Item.ILField(fieldInfo)) | ||
| ] | ||
|
|
||
| let getEventItems () = | ||
| [ let events = | ||
| infoReader.GetEventInfosOfType(None, ad, m, ty) | ||
| |> List.groupBy (fun e -> e.EventName) | ||
|
|
||
| { nenv with eUnqualifiedItems = nenv.eUnqualifiedItems.AddAndMarkAsCollapsible items } | ||
| for (eventName, eventInfos) in events do | ||
| let eventInfos = eventInfos |> List.filter (fun e -> e.IsStatic) | ||
| for eventInfo in eventInfos do | ||
| yield KeyValuePair(eventName, Item.Event(eventInfo)) | ||
| ] | ||
|
|
||
| let items = | ||
| [ | ||
| let propAndMethGroups = | ||
| getPropItems () @ getMethItems () | ||
| |> List.groupBy (fun pair -> pair.Key) | ||
|
|
||
| for (_, items) in propAndMethGroups do | ||
| // This is to handle the current behavior with qualified extension members: | ||
| // Extension properties will shadow all extension methods that share the same name no matter the order in which the extensions are opened from modules. | ||
| // TODO: What happens with CSharp-style extension methods? | ||
| let sortedItems = | ||
| items | ||
| |> List.sortBy (fun pair -> | ||
| match pair.Value with | ||
| | Item.Property (_, [propInfo]) -> not propInfo.IsExtensionMember | ||
| | Item.MethodGroup (_, methGroup, _) -> methGroup |> List.exists (fun x -> not x.IsExtensionMember) | ||
| | _ -> false) | ||
| match sortedItems with | ||
| | item :: _ -> yield item | ||
| | _ -> () | ||
|
|
||
| yield! getFieldItems () | ||
| yield! getEventItems () | ||
| ] | ||
|
|
||
| { nenv with | ||
| eUnqualifiedItems = | ||
| (nenv.eUnqualifiedItems, items) | ||
| ||> List.fold (fun x (KeyValue(k, v)) -> | ||
| match x.TryGetValue k with | ||
| | true, existingItem -> | ||
| match existingItem, v with | ||
|
|
||
| // Combine methods groups. This allows overloading on methods from different classes. Mimics C# behavior. | ||
| | Item.MethodGroup (_, minfosCurrent, None), Item.MethodGroup (_, minfosNew, None) -> | ||
| let minfos = | ||
| (minfosNew, minfosCurrent) | ||
| ||> List.fold (fun minfos minfo1 -> | ||
| // Shadow methods with the same signature. | ||
| // F# specific behavior; the order of opening is significant and ambiguities are shadowed. | ||
| // In C#, an error would occur and asks the developer to resolve the ambiguity. | ||
| // We allow UoM (units of measure) to be significant in overloading here. | ||
| if minfosCurrent |> List.exists (fun minfo2 -> MethInfosEquivByNameAndSig Erasure.EraseNone true g amap m minfo1 minfo2) then | ||
| minfos | ||
| else | ||
| minfo1 :: minfos | ||
| ) | ||
| x.Add(k, Item.MethodGroup (k, minfos, None)) | ||
|
|
||
| // Methods will always shadow properties, events, and fields with the same name; order of opening does not matter in this case. | ||
| // This is to mimic the C# behavior of opening multiple static classes. | ||
| | Item.MethodGroup _, Item.Property _ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems fine, will need test cases and RFC update
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, for sure. This is to mimic opening multiple static classes in C# and what their behavior is. |
||
| | Item.MethodGroup _, Item.Event _ | ||
| | Item.MethodGroup _, Item.ILField _ -> x | ||
| | _ -> x.Add(k, v) | ||
| | _ -> x.Add(k, v)) | ||
| } | ||
| else | ||
| nenv | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
need to pass
adhereThere 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.
whoops