-
Notifications
You must be signed in to change notification settings - Fork 850
C# fields in SRTP support #19417
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
base: main
Are you sure you want to change the base?
C# fields in SRTP support #19417
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2164,7 +2164,7 @@ let GenWitnessExpr amap g m (traitInfo: TraitConstraintInfo) argExprs = | |||||
|
|
||||||
| let sln = | ||||||
| match traitInfo.Solution with | ||||||
| | None -> Choice5Of5() | ||||||
| | None -> Choice6Of6() | ||||||
| | Some sln -> | ||||||
|
|
||||||
| // Given the solution information, reconstruct the MethInfo for the solution | ||||||
|
|
@@ -2179,25 +2179,54 @@ let GenWitnessExpr amap g m (traitInfo: TraitConstraintInfo) argExprs = | |||||
| | Some ilActualTypeRef -> | ||||||
| let actualTyconRef = ImportILTypeRef amap m ilActualTypeRef | ||||||
| MethInfo.CreateILExtensionMeth(amap, m, origTy, actualTyconRef, None, mdef) | ||||||
| Choice1Of5 (ilMethInfo, minst, staticTyOpt) | ||||||
| Choice1Of6 (ilMethInfo, minst, staticTyOpt) | ||||||
|
|
||||||
| | FSMethSln(ty, vref, minst, staticTyOpt) -> | ||||||
| Choice1Of5 (FSMeth(g, ty, vref, None), minst, staticTyOpt) | ||||||
| Choice1Of6 (FSMeth(g, ty, vref, None), minst, staticTyOpt) | ||||||
|
|
||||||
| | FSRecdFieldSln(tinst, rfref, isSetProp) -> | ||||||
| Choice2Of5 (tinst, rfref, isSetProp) | ||||||
| Choice2Of6 (tinst, rfref, isSetProp) | ||||||
|
|
||||||
| | FSAnonRecdFieldSln(anonInfo, tinst, i) -> | ||||||
| Choice3Of5 (anonInfo, tinst, i) | ||||||
| Choice3Of6 (anonInfo, tinst, i) | ||||||
|
|
||||||
| | ClosedExprSln expr -> | ||||||
| Choice4Of5 expr | ||||||
| Choice4Of6 expr | ||||||
|
|
||||||
| | ILFieldSln(ty, tinst, ilfref, isStatic, isSet) -> | ||||||
| Choice5Of6 (ty, tinst, ilfref, isStatic, isSet) | ||||||
|
|
||||||
| | BuiltInSln -> | ||||||
| Choice5Of5 () | ||||||
| Choice6Of6 () | ||||||
|
|
||||||
| match sln with | ||||||
| | Choice1Of5(minfo, methArgTys, staticTyOpt) -> | ||||||
| | Choice5Of6(ty, tinst, ilfref, isStatic, isSet) -> | ||||||
| let declaringTyconRef = ImportILTypeRef amap m ilfref.DeclaringTypeRef | ||||||
| let isStruct = isStructTy g (generalizedTyconRef g declaringTyconRef) | ||||||
| let boxity = if isStruct then ILBoxity.AsValue else ILBoxity.AsObject | ||||||
| let fspec = mkILFieldSpec (ilfref, mkILNamedTy boxity ilfref.DeclaringTypeRef []) | ||||||
|
|
||||||
| match isStatic, isSet with | ||||||
| | false, false -> | ||||||
| // Instance getter: ldfld | ||||||
| Some(Expr.Op(TOp.ILAsm([ mkNormalLdfld fspec ], [ ty ]), tinst, argExprs, m)) | ||||||
| | false, true -> | ||||||
| // Instance setter: stfld (handle struct address-taking) | ||||||
| if isStruct && not (isByrefTy g (tyOfExpr g argExprs[0])) then | ||||||
| let wrap, h', _readonly, _writeonly = | ||||||
| mkExprAddrOfExpr g true false PossiblyMutates argExprs[0] None m | ||||||
|
||||||
| mkExprAddrOfExpr g true false PossiblyMutates argExprs[0] None m | |
| mkExprAddrOfExpr g true false DefinitelyMutates argExprs[0] None m |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -1155,4 +1155,7 @@ | |||||||
| <data name="NoConstructorsAvailableForType" xml:space="preserve"> | ||||||||
| <value>No constructors are available for the type '{0}'</value> | ||||||||
| </data> | ||||||||
| <data name="featureSupportILFieldsInSRTP" xml:space="preserve"> | ||||||||
| <value>Support for .NET fields in SRTP member constraints</value> | ||||||||
| </data> | ||||||||
|
Comment on lines
+1158
to
+1160
|
||||||||
| <data name="featureSupportILFieldsInSRTP" xml:space="preserve"> | |
| <value>Support for .NET fields in SRTP member constraints</value> | |
| </data> |
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.
The IL-field setter path can resolve even when the member-constraint shape isn’t a valid setter.
fieldSearchaccepts anyset_name regardless ofargTyslength, and later only checks the argument type whenargTysis exactly[argTy](otherwise it silently skips). Consider requiringargTys.Length = 1forset_(andargTys.IsEmptyforget_) before returning a field solution, so malformed signatures don’t bind to fields.