-
Notifications
You must be signed in to change notification settings - Fork 21
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
Allow object expression without overrides #632
Comments
This makes total sense, there is no reason why we shouldn't allow this. Marking as approved-in-principle |
Does this need an RFC? |
@7sharp9 It probably does. Can you please create one? |
Im looking into writing the RFC but I think it should be possible to remove this limitation for abstract classes and not abstract classes as it already possible for interfaces. cc @dsyme @vzarytovskii See WIP implementation dotnet/fsharp#17387 type IFoo = interface end
type Class() =
do printfn "Hello"
member this.Method() = ()
let a = { new Class() with member this.ToString() = "" } // We are force to override ToString to make it work
let b = { new Class() interface IFoo } // Or implement a marker interface
[<AbstractClass>]
type AbstractClass() =
do printfn "Hello"
let c = { new AbstractClass() with member this.ToString() = "" } // We are force to override ToString to make it work
let d = { new AbstractClass() interface IFoo } // Or implement a marker interface
// It should be possible to remove this limitation for abstract classes and not abstract classes as it already possible for interfaces
let e = { new IFoo } |
I am fine with it, as long as @dsyme is (he may have specific reason why it is explicitly disallowed currently), but it feels more uniform (however confusing, as it's "do the same thing in two different ways"). dotnet fsi
Microsoft (R) F# Interactive version 12.8.400.0 for F# 8.0
Copyright (c) Microsoft Corporation. All Rights Reserved.
For help type #help;;
> type ClassEnd() = class end
- ;;
type ClassEnd =
new: unit -> ClassEnd
> { new ClassEnd() };;
{ new ClassEnd() };;
^^^^^^^^^^^^^^^^^^
/Users/u/code/fsharp/stdin(6,1): error FS0738: Invalid object expression. Objects without overrides or interfaces should use the expression form 'new Type(args)' without braces. |
This can be closed. I implemented it in dotnet/fsharp#17387 |
Described here
https://stackoverflow.com/questions/8154730/object-expression-for-abstract-class-without-abstract-members
I propose we allow it because it's necessary when base class has protected constructor.
The existing way of approaching this problem in F# is ...
Define top level class that only invokes base constructor.
Pros and Cons
The advantages of making this adjustment to F# are ...
Better inter-op with existing NET libraries.
The disadvantages of making this adjustment to F# are ...
Extra work.
Extra information
Estimated cost (XS, S, M, L, XL, XXL):
No idea.
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
The text was updated successfully, but these errors were encountered: