Skip to content
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

Warning or error is raised when consuming IL Event with an Obsolete attribute #14006

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Compiler/Checking/AttributeChecking.fs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,9 @@ let CheckEntityAttributes g (tcref: TyconRef) m =
CheckILAttributes g (isByrefLikeTyconRef g m tcref) tcref.ILTyconRawMetadata.CustomAttrs m
else
CheckFSharpAttributes g tcref.Attribs m

let CheckILEventAttributes g (tcref: TyconRef) cattrs m =
CheckILAttributes g (isByrefLikeTyconRef g m tcref) cattrs m

/// Check the attributes associated with a method, returning warnings and errors as data.
let CheckMethInfoAttributes g m tyargsOpt (minfo: MethInfo) =
Expand Down
2 changes: 2 additions & 0 deletions src/Compiler/Checking/AttributeChecking.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,5 @@ val IsSecurityAttribute:
val IsSecurityCriticalAttribute: g: TcGlobals -> Attrib -> bool

val IsAssemblyVersionAttribute: g: TcGlobals -> Attrib -> bool

val CheckILEventAttributes: g: TcGlobals -> tcref: TyconRef -> cattrs: ILAttributes -> m: range -> OperationResult<unit>
4 changes: 3 additions & 1 deletion src/Compiler/Checking/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9095,7 +9095,9 @@ and TcEventItemThen (cenv: cenv) overallTy env tpenv mItem mExprAndItem objDetai
let (SigOfFunctionForDelegate(delInvokeMeth, delArgTys, _, _)) = GetSigOfFunctionForDelegate cenv.infoReader delTy mItem ad
let objArgs = Option.toList (Option.map fst objDetails)
MethInfoChecks g cenv.amap true None objArgs env.eAccessRights mItem delInvokeMeth


CheckILEventAttributes g einfo.DeclaringTyconRef (einfo.GetCustomAttrs()) mItem |> CommitOperationResult

// This checks for and drops the 'object' sender
let argsTy = ArgsTypeOfEventInfo cenv.infoReader mItem ad einfo
if not (slotSigHasVoidReturnTy (delInvokeMeth.GetSlotSig(cenv.amap, mItem))) then errorR (nonStandardEventError einfo.EventName mItem)
Expand Down
6 changes: 6 additions & 0 deletions src/Compiler/Checking/infos.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2275,6 +2275,12 @@ type EventInfo =
| ProvidedEvent (_, ei, _) -> ProvidedEventInfo.TaintedGetHashCode ei
#endif
override x.ToString() = "event " + x.EventName

/// Get custom attributes for events (only applicable for IL events)
member x.GetCustomAttrs() =
match x with
| ILEvent(ILEventInfo(_, ilEventDef))-> ilEventDef.CustomAttrs
| _ -> ILAttributes.Empty

//-------------------------------------------------------------------------
// Helpers associated with getting and comparing method signatures
Expand Down
3 changes: 3 additions & 0 deletions src/Compiler/Checking/infos.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,9 @@ type EventInfo =
/// Get the delegate type associated with the event.
member GetDelegateType: amap: ImportMap * m: range -> TType

/// Get custom attributes for events (only applicable for IL events)
member GetCustomAttrs: unit -> ILAttributes

/// An exception type used to raise an error using the old error system.
///
/// Error text: "A definition to be compiled as a .NET event does not have the expected form. Only property members can be compiled as .NET events."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,7 @@ Class.ObsoleteEvent |> ignore
(Warning 44, Line 3, Col 1, Line 3, Col 20, "This construct is deprecated. Field is obsolete");
(Warning 44, Line 4, Col 1, Line 4, Col 21, "This construct is deprecated. Method is obsolete");
(Warning 44, Line 5, Col 1, Line 5, Col 23, "This construct is deprecated. Property is obsolete")
(Warning 44, Line 6, Col 1, Line 6, Col 20, "This construct is deprecated. Event is obsolete")
]

[<Fact>]
Expand Down Expand Up @@ -955,4 +956,5 @@ Class.ObsoleteEvent |> ignore
(Error 101, Line 3, Col 1, Line 3, Col 20, "This construct is deprecated. Field is obsolete");
(Error 101, Line 4, Col 1, Line 4, Col 21, "This construct is deprecated. Method is obsolete");
(Error 101, Line 5, Col 1, Line 5, Col 23, "This construct is deprecated. Property is obsolete")
(Error 101, Line 6, Col 1, Line 6, Col 20, "This construct is deprecated. Event is obsolete")
]