Skip to content

Conversation

@T-Gro
Copy link
Member

@T-Gro T-Gro commented Nov 18, 2022

F# adds a Message property to each Exception, calling sprintfn "%A".

However, when either a custom field or a public property with the name Message is being added manually, it should win over the generated one and override what gets called on the Exception.Message property of the top level class.

exception MyCustomExc of Message:string
let f() =
    try
        raise (MyCustomExc("This should be the message!"))
    with
        | MyCustomExc m as e  -> e.Message

@T-Gro T-Gro requested a review from a team as a code owner November 18, 2022 13:37
@T-Gro T-Gro added this to the November-2022 milestone Nov 18, 2022
@T-Gro T-Gro self-assigned this Nov 18, 2022
Copy link
Contributor

@psfinaki psfinaki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks for the intense testing :)

@vzarytovskii
Copy link
Member

Fixes #1602

Copy link
Member

@vzarytovskii vzarytovskii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please check if both cases which are mentioned in #1602 are covered in tests to see if they're also fixed?

@KevinRansom KevinRansom merged commit 5f0313e into dotnet:main Nov 21, 2022
@T-Gro
Copy link
Member Author

T-Gro commented Nov 22, 2022

Could you please check if both cases which are mentioned in #1602 are covered in tests to see if they're also fixed?

This thing works and is supported now:

module Override =
    exception SomeException of Message: string 

This thing is and never was valid F# (even if I replace Message with any other identifier, it is not specific to it):

module Override =
    exception SomeException of Message: string with
        override this.Message = this.Message

The "chatty" approach still works, however now it is of course a lot easier to simply name the property "Message" and do not deal with any override at all.

module Override =
    exception SomeException of info: string with
        override this.Message = this.info

@T-Gro
Copy link
Member Author

T-Gro commented Nov 22, 2022

Will crosspost to that issue as well.

@T-Gro T-Gro deleted the error-duplicate-exception-message-property branch November 22, 2022 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Error in pass2 for type MyExceptionTypeException, error: duplicate entry 'get_Message' in method table

4 participants