Skip to content
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 #17387

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f72567b
Allow object expression without overrides
edgarfgp Jul 5, 2024
10baa90
release notes
edgarfgp Jul 6, 2024
cdb0f08
Lets try this version
edgarfgp Jul 6, 2024
26334eb
WIP
edgarfgp Jul 29, 2024
6489ae4
release notes
edgarfgp Jul 29, 2024
8022d39
Update tests
edgarfgp Jul 29, 2024
8c4ae6c
more tests
edgarfgp Jul 30, 2024
217e6ff
more tests
edgarfgp Jul 30, 2024
49486ee
LanguageFeature.AllowObjectExpressionWithoutOverrides
edgarfgp Aug 7, 2024
2fabb99
reduce diff
edgarfgp Aug 7, 2024
1397d32
one more test
edgarfgp Aug 8, 2024
2d2b7de
more tests
edgarfgp Aug 9, 2024
0766d36
WIP more tests
edgarfgp Aug 13, 2024
1ae3ff5
fix merge
edgarfgp Aug 13, 2024
4a26619
More tests
edgarfgp Aug 13, 2024
cb9b78e
Fix failing tests
edgarfgp Aug 13, 2024
2233c5f
more tests
edgarfgp Aug 14, 2024
254553b
Merge branch 'main' into allow-object-expression-without-overrides
edgarfgp Aug 14, 2024
746dbc4
Merge branch 'main' into allow-object-expression-without-overrides
edgarfgp Aug 14, 2024
e0116ce
re-structure tests to make easier to review
edgarfgp Aug 15, 2024
79be202
Merge branch 'allow-object-expression-without-overrides' of github.co…
edgarfgp Aug 15, 2024
5d9d4b1
Support non abstract too
edgarfgp Aug 15, 2024
d4fd47d
Merge branch 'main' into allow-object-expression-without-overrides
edgarfgp Aug 15, 2024
c9d8ed4
Merge branch 'main' into allow-object-expression-without-overrides
edgarfgp Aug 16, 2024
1ef6ccc
Merge branch 'main' into allow-object-expression-without-overrides
edgarfgp Aug 19, 2024
5d60025
Merge branch 'main' into allow-object-expression-without-overrides
edgarfgp Aug 19, 2024
17277d1
withLangVersion90
edgarfgp Aug 19, 2024
38cb08d
Merge branch 'allow-object-expression-without-overrides' of github.co…
edgarfgp Aug 19, 2024
78585a2
Merge branch 'main' into allow-object-expression-without-overrides
edgarfgp Aug 19, 2024
155d352
Merge branch 'main' into allow-object-expression-without-overrides
edgarfgp Aug 20, 2024
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
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/9.0.100.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* Sink: report function domain type ([PR #17470](https://github.com/dotnet/fsharp/pull/17470))
* Allow access modifies to auto properties getters and setters ([Language suggestion #430](https://github.com/fsharp/fslang-suggestions/issues/430), [PR 16687](https://github.com/dotnet/fsharp/pull/16687), [PR 16861](https://github.com/dotnet/fsharp/pull/16861), [PR 17522](https://github.com/dotnet/fsharp/pull/17522))
* Render C# nullable-analysis attributes in tooltips ([PR #17485](https://github.com/dotnet/fsharp/pull/17485))
* Allow object expression without overrides. ([Language suggestion #632](https://github.com/fsharp/fslang-suggestions/issues/632), [PR #17387](https://github.com/dotnet/fsharp/pull/17387))

### Changed

Expand Down
2 changes: 2 additions & 0 deletions docs/release-notes/.Language/preview.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* Allow #nowarn to support the FS prefix on error codes to disable warnings ([Issue #17206](https://github.com/dotnet/fsharp/issues/16447), [PR #17209](https://github.com/dotnet/fsharp/pull/17209))
* Allow ParsedHashDirectives to have argument types other than strings ([Issue #17240](https://github.com/dotnet/fsharp/issues/16447), [PR #17209](https://github.com/dotnet/fsharp/pull/17209))
* Support empty-bodied computation expressions. ([Language suggestion #1232](https://github.com/fsharp/fslang-suggestions/issues/1232), [PR #17352](https://github.com/dotnet/fsharp/pull/17352))
* Allow object expression without overrides. ([Language suggestion #632](https://github.com/fsharp/fslang-suggestions/issues/632), [PR #17387](https://github.com/dotnet/fsharp/pull/17387))


### Fixed

Expand Down
17 changes: 10 additions & 7 deletions src/Compiler/Checking/Expressions/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6791,7 +6791,8 @@ and TcRecordConstruction (cenv: cenv) (overallTy: TType) isObjExpr env tpenv wit
UnifyTypes cenv env m overallTy objTy

// Types with implicit constructors can't use record or object syntax: all constructions must go through the implicit constructor
if tycon.MembersOfFSharpTyconByName |> NameMultiMap.existsInRange (fun v -> v.IsIncrClassConstructor) then
let supportsObjectExpressionWithoutOverrides = isObjExpr && g.langVersion.SupportsFeature(LanguageFeature.AllowObjectExpressionWithoutOverrides)
if not supportsObjectExpressionWithoutOverrides && tycon.MembersOfFSharpTyconByName |> NameMultiMap.existsInRange (fun v -> v.IsIncrClassConstructor) then
errorR(Error(FSComp.SR.tcConstructorRequiresCall(tycon.DisplayName), m))

let fspecs = tycon.TrueInstanceFieldsAsList
Expand Down Expand Up @@ -7139,7 +7140,8 @@ and TcObjectExpr (cenv: cenv) env tpenv (objTy, realObjTy, argopt, binds, extraI
let isRecordTy = tcref.IsRecordTycon
let isInterfaceTy = isInterfaceTy g objTy
let isFSharpObjModelTy = isFSharpObjModelTy g objTy
let isOverallTyAbstract = HasFSharpAttribute g g.attrib_AbstractClassAttribute tcref.Attribs
let isOverallTyAbstract = HasFSharpAttribute g g.attrib_AbstractClassAttribute tcref.Attribs || isAbstractTycon tcref.Deref

if not isRecordTy && not isInterfaceTy && isSealedTy g objTy then errorR(Error(FSComp.SR.tcCannotCreateExtensionOfSealedType(), mNewExpr))

CheckSuperType cenv objTy mObjTy
Expand Down Expand Up @@ -7206,8 +7208,9 @@ and TcObjectExpr (cenv: cenv) env tpenv (objTy, realObjTy, argopt, binds, extraI

let overridesAndVirts, tpenv = ComputeObjectExprOverrides cenv env tpenv impls

// 2. check usage conditions
overridesAndVirts |> List.iter (fun (m, implTy, dispatchSlots, dispatchSlotsKeyed, availPriorOverrides, overrides) ->
// 2. check usage conditions
for ovd in overridesAndVirts do
let (m, implTy, dispatchSlots, dispatchSlotsKeyed, availPriorOverrides, overrides) = ovd
let overrideSpecs = overrides |> List.map fst
let hasStaticMembers = dispatchSlots |> List.exists (fun reqdSlot -> not reqdSlot.MethodInfo.IsInstance)
if hasStaticMembers then
Expand All @@ -7217,7 +7220,6 @@ and TcObjectExpr (cenv: cenv) env tpenv (objTy, realObjTy, argopt, binds, extraI

if not hasStaticMembers then
DispatchSlotChecking.CheckDispatchSlotsAreImplemented (env.DisplayEnv, cenv.infoReader, m, env.NameEnv, cenv.tcSink, isOverallTyAbstract, true, implTy, dispatchSlots, availPriorOverrides, overrideSpecs) |> ignore
)

// 3. create the specs of overrides
let allTypeImpls =
Expand Down Expand Up @@ -7249,8 +7251,9 @@ and TcObjectExpr (cenv: cenv) env tpenv (objTy, realObjTy, argopt, binds, extraI
let objtyR, overrides' = allTypeImpls.Head
assert (typeEquiv g objTy objtyR)
let extraImpls = allTypeImpls.Tail

if not isInterfaceTy && (isOverallTyAbstract && overrides'.IsEmpty) && extraImpls.IsEmpty then
let supportsObjectExpressionWithoutOverrides = g.langVersion.SupportsFeature(LanguageFeature.AllowObjectExpressionWithoutOverrides)

if not supportsObjectExpressionWithoutOverrides && not isInterfaceTy && overrides'.IsEmpty && extraImpls.IsEmpty then
errorR (Error(FSComp.SR.tcInvalidObjectExpressionSyntaxForm (), mWholeExpr))

// 4. Build the implementation
Expand Down
1 change: 1 addition & 0 deletions src/Compiler/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1778,3 +1778,4 @@ featureEmptyBodiedComputationExpressions,"Support for computation expressions wi
3870,parsExpectingUnionCaseField,"Expecting union case field"
featureAllowAccessModifiersToAutoPropertiesGettersAndSetters,"Allow access modifiers to auto properties getters and setters"
3871,tcAccessModifiersNotAllowedInSRTPConstraint,"Access modifiers cannot be applied to an SRTP constraint."
featureAllowObjectExpressionWithoutOverrides,"Allow object expressions without overrides"
3 changes: 3 additions & 0 deletions src/Compiler/Facilities/LanguageFeatures.fs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ type LanguageFeature =
| LowerSimpleMappingsInComprehensionsToFastLoops
| ParsedHashDirectiveArgumentNonQuotes
| EmptyBodiedComputationExpressions
| AllowObjectExpressionWithoutOverrides

/// LanguageVersion management
type LanguageVersion(versionText) =
Expand Down Expand Up @@ -217,6 +218,7 @@ type LanguageVersion(versionText) =
LanguageFeature.EnforceAttributeTargets, previewVersion // not enabled because: https://github.com/dotnet/fsharp/issues/17514
LanguageFeature.FromEndSlicing, previewVersion // Unfinished features --- needs work
LanguageFeature.AllowAccessModifiersToAutoPropertiesGettersAndSetters, previewVersion
LanguageFeature.AllowObjectExpressionWithoutOverrides, previewVersion
]

static let defaultLanguageVersion = LanguageVersion("default")
Expand Down Expand Up @@ -372,6 +374,7 @@ type LanguageVersion(versionText) =
FSComp.SR.featureLowerSimpleMappingsInComprehensionsToFastLoops ()
| LanguageFeature.ParsedHashDirectiveArgumentNonQuotes -> FSComp.SR.featureParsedHashDirectiveArgumentNonString ()
| LanguageFeature.EmptyBodiedComputationExpressions -> FSComp.SR.featureEmptyBodiedComputationExpressions ()
| LanguageFeature.AllowObjectExpressionWithoutOverrides -> FSComp.SR.featureAllowObjectExpressionWithoutOverrides ()

/// Get a version string associated with the given feature.
static member GetFeatureVersionString feature =
Expand Down
1 change: 1 addition & 0 deletions src/Compiler/Facilities/LanguageFeatures.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ type LanguageFeature =
| LowerSimpleMappingsInComprehensionsToFastLoops
| ParsedHashDirectiveArgumentNonQuotes
| EmptyBodiedComputationExpressions
| AllowObjectExpressionWithoutOverrides

/// LanguageVersion management
type LanguageVersion =
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.pt-BR.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.ru.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.tr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.zh-Hans.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Compiler/xlf/FSComp.txt.zh-Hant.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading