Skip to content

Allow object expression without overrides - #17387

Merged
vzarytovskii merged 30 commits into
dotnet:mainfrom
edgarfgp:allow-object-expression-without-overrides
Aug 20, 2024
Merged

Allow object expression without overrides#17387
vzarytovskii merged 30 commits into
dotnet:mainfrom
edgarfgp:allow-object-expression-without-overrides

Conversation

@edgarfgp

@edgarfgpedgarfgp commented Jul 5, 2024

Copy link
Copy Markdown
Contributor

Description

Add support for object expression without overrides.

Before

To create an object expression without overrides, the user has to override a member, even if it is not necessary.

typeIFirst=interfaceend[<AbstractClass>]typeClassEnd()=classend// FS0738 Invalid object expression. Objects without overrides or interfaces should use the expression form 'new Type(args)' without braces.letobjExpr={new ClassEnd()}// Workaround: override a member like ToString, Equals, GetHashCode, etc.letobjExpr={new ClassEnd()withmemberthis.ToString()="ClassEnd"}// Workaround: implement a marker interfaceletobjExpr={new ClassEnd()interface IFirst }typeClass()=classend//FS0738 Invalid object expression. Objects without overrides or interfaces should use the expression form 'new Type(args)' without braces.letobjExpr={new Class()}// Workaround: override a member like ToString, Equals, GetHashCode, etc.letobjExpr={new Class()withmemberthis.ToString()="ClassEnd"}// Workaround: implement a marker interfaceletobjExpr={new Class()interface IFirst }

After

We won't need to use any workaround to use classes(abstract or non-abstract) in object expressions.

[<AbstractClass>]typeAbstractClass()=classend// OkletobjExpr={new AbstractClass()}typeClass()=classend// OkletobjExpr={new Class()}

Checklist

  • Test cases added
  • Release notes entry updated

@github-actions

github-actionsBot commented Jul 5, 2024

Copy link
Copy Markdown
Contributor

❗ Release notes required


✅ Found changes and release notes in following paths:

Change pathRelease notes pathDescription
src/Compilerdocs/release-notes/.FSharp.Compiler.Service/9.0.100.md
LanguageFeatures.fsidocs/release-notes/.Language/preview.md

@edgarfgpedgarfgp mentioned this pull request Jul 7, 2024
2 tasks
@edgarfgpedgarfgp reopened this Jul 29, 2024
@edgarfgpedgarfgp reopened this Jul 30, 2024
@edgarfgpedgarfgp changed the title Allow object expression without overridesAllow object expression without overrides when base class has protected constructorJul 30, 2024
@edgarfgpedgarfgp changed the title Allow object expression without overrides when base class has protected constructorAllow object expression without overridesAug 15, 2024
@edgarfgp
edgarfgp marked this pull request as ready for review August 16, 2024 06:14
@edgarfgp
edgarfgp requested a review from a team as a code ownerAugust 16, 2024 06:14
@vzarytovskii

Copy link
Copy Markdown
Member

Can be merged after RFC is approved by Don

…m:edgarfgp/fsharp into allow-object-expression-without-overrides

@psfinakipsfinaki left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fabulous work. Thanks for adding tests for the old versions as well. Great stuff Edgar!

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants

@edgarfgp@vzarytovskii@psfinaki