Skip to content
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/AbstractIL/il.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2073,6 +2073,9 @@ type ILMethodDef
member x.WithAbstract(condition) =
x.With(attributes = (x.Attributes |> conditionalAdd condition MethodAttributes.Abstract))

member x.WithVirtual(condition) =
x.With(attributes = (x.Attributes |> conditionalAdd condition MethodAttributes.Virtual))

member x.WithAccess(access) =
x.With(
attributes =
Expand Down
1 change: 1 addition & 0 deletions src/Compiler/AbstractIL/il.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,7 @@ type ILMethodDef =
member internal WithHideBySig: bool -> ILMethodDef
member internal WithFinal: bool -> ILMethodDef
member internal WithAbstract: bool -> ILMethodDef
member internal WithVirtual: bool -> ILMethodDef
member internal WithAccess: ILMemberAccess -> ILMethodDef
member internal WithNewSlot: ILMethodDef
member internal WithSecurity: bool -> ILMethodDef
Expand Down
9 changes: 8 additions & 1 deletion src/Compiler/CodeGen/IlxGen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11429,7 +11429,13 @@ and GenExnDef cenv mgbuf eenv m (exnc: Tycon) =
let ilFieldName = ComputeFieldName exnc fld

let ilMethodDef =
mkLdfldMethodDef (ilMethName, reprAccess, false, ilThisTy, ilFieldName, ilPropType, [])
let def =
mkLdfldMethodDef (ilMethName, reprAccess, false, ilThisTy, ilFieldName, ilPropType, [])

if ilPropName = "Message" then
def.WithVirtual(true)
else
def

let ilFieldDef =
mkILInstanceField (ilFieldName, ilPropType, None, ILMemberAccess.Assembly)
Expand Down Expand Up @@ -11516,6 +11522,7 @@ and GenExnDef cenv mgbuf eenv m (exnc: Tycon) =
cenv.g.langVersion.SupportsFeature(LanguageFeature.BetterExceptionPrinting)
&& not (exnc.HasMember g "get_Message" [])
&& not (exnc.HasMember g "Message" [])
&& not (fspecs |> List.exists (fun rf -> rf.DisplayNameCore = "Message"))
then
yield! GenPrintingMethod cenv eenv "get_Message" ilThisTy m
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
exception MyCustomExc of field:int
let f() =
try
raise (MyCustomExc(42))
with
| MyCustomExc _ as e -> e.Message


let result = f()
printfn "%s" result
if result <> "MyCustomExc 42" then failwith "Failed: 1"

Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,34 @@ module ExceptionDefinition =
|> compileExeAndRun
|> shouldSucceed

// SOURCE=AddMessageProperty.fs # AddMessageProperty
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"AddMessageProperty.fs"|])>]
let``AddMessageProperty`` compilation =
compilation
|> asExe
|> withOptions ["--warnaserror+"; "--nowarn:988"]
|> compileExeAndRun
|> shouldSucceed

// SOURCE=ManualMessagePropertyWinsOverAutomaticOne.fs # ManualMessagePropertyWinsOverAutomaticOne
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"ManualMessagePropertyWinsOverAutomaticOne.fs"|])>]
let``ManualMessagePropertyWinsOverAutomaticOne`` compilation =
compilation
|> asExe
|> withOptions ["--warnaserror+"; "--nowarn:988"]
|> compileExeAndRun
|> shouldSucceed

// SOURCE=PrivateMessagePropertyIsNotReplacingBuiltinMessage.fs # PrivateMessagePropertyIsNotReplacingBuiltinMessage
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"PrivateMessagePropertyIsNotReplacingBuiltinMessage.fs"|])>]
let``PrivateMessagePropertyIsNotReplacingBuiltinMessage`` compilation =
compilation
|> asExe
|> withOptions ["--nowarn:988"]
|> ignoreWarnings
|> compileExeAndRun
|> shouldSucceed

// SOURCE=CatchWOTypecheck01.fs # CatchWOTypeCheck01
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"CatchWOTypecheck01.fs"|])>]
let``CatchWOTypecheck01_fs`` compilation =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
exception MyCustomExc of Message:string
let f() =
try
raise (MyCustomExc("This should be the message!"))
with
| MyCustomExc m as e -> e.Message


let result = f()
printfn "%s" result
if result <> "This should be the message!" then failwith $"Failed: 1. Message is '{result}' instead"

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
exception MyCustomExc of int
with
member private this.Message = "This must remain secret!"
end

let f() =
try
raise (MyCustomExc(42))
with
| e -> e.Message


let result = f()
printfn "%s" result
if result = "This must remain secret!" then failwith $"Failed: 1. Secret private string was leaked."