-
Notifications
You must be signed in to change notification settings - Fork 830
Open
Open
Copy link
Labels
Area-Compiler-CheckingType checking, attributes and all aspects of logic checkingType checking, attributes and all aspects of logic checkingBugImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.(Internal MS Team use only) Describes an issue with moderate impact on existing code.
Milestone
Description
If the static do block of a class attempts to call a protected static member of a base class, a MethodAccessException is raised because the code from the do block is moved outside the derived class by the compiler
#nowarn "44" // using Uri.EscapeString just because it's protected static
type C(str : string) =
inherit System.Uri(str)
static do
System.Uri.EscapeString("data") |> ignore
C("hello") |> ignoreExpected behavior
The method call should succeed, since the static do is the equivalent to C#'s static constructor, or a warning should be produced that while this will compile it won't work.
Actual behavior
A MethodAccessException is raised on the call
Known workarounds
Move the method call into a static member of the derived class, and call it from the static do block:
static do
C.Do()
static member internal Do() =
System.Uri.EscapeString("data") |> ignoreMetadata
Metadata
Assignees
Labels
Area-Compiler-CheckingType checking, attributes and all aspects of logic checkingType checking, attributes and all aspects of logic checkingBugImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.(Internal MS Team use only) Describes an issue with moderate impact on existing code.
Type
Projects
Status
New