* Respect the order of SynBindings in SynMemberDefn.GetSetMember.

* Remove unnecessary tests.

* Add release notes entry for SynMemberDefn.GetSetMember.
This commit is contained in:
Florian Verdonck 2022-07-06 17:21:23 +02:00 коммит произвёл GitHub
Родитель 3e66a60160
Коммит 267d0a57f2
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 45 добавлений и 86 удалений

Просмотреть файл

@ -34,6 +34,7 @@ These release notes track our current efforts to document changes to the F# proj
`a + b` is parsed as `SynLongIdent([op_Addition], [], [Some (OriginalNotation "+")])`.
* `SynMeasure` was extended with [SynMeasure.Paren](https://fsharp.github.io/fsharp-compiler-docs/reference/fsharp-compiler-syntax-synmeasure.html#Paren) case.
* Dynamic expressions (like `x?y`) are now represented as [SynExpr.Dynamic](https://fsharp.github.io/fsharp-compiler-docs/reference/fsharp-compiler-syntax-synexpr.html#Dynamic) in the Untyped Syntax Tree.
* Members with `get` and/or `set` are now represented as [SynMemberDefn.GetSetMember](https://fsharp.github.io/fsharp-compiler-docs/reference/fsharp-compiler-syntax-synmemberdefn.html#GetSetMember) in the Untyped Syntax Tree.
### F# 6.0 / Visual Studio 17.0

Просмотреть файл

@ -764,42 +764,17 @@ let mkSynMemberDefnGetSet
let setter = tryMkSynMemberDefnMember s
match getter, setter with
| Some (SynMemberDefn.Member (getBinding, mGet), getIdent), Some (SynMemberDefn.Member (setBinding, mSet), setIdent) ->
let range = unionRanges mGet mSet
| Some (SynMemberDefn.Member (getBinding, m1), GetIdent mGet), Some (SynMemberDefn.Member (setBinding, m2), SetIdent mSet)
| Some (SynMemberDefn.Member (setBinding, m1), SetIdent mSet), Some (SynMemberDefn.Member (getBinding, m2), GetIdent mGet) ->
let range = unionRanges m1 m2
let trivia =
match getIdent, setIdent with
| GetIdent mGet, SetIdent mSet
| SetIdent mSet, GetIdent mGet ->
{
WithKeyword = mWith
GetKeyword = Some mGet
AndKeyword = mAnd
SetKeyword = Some mSet
}
| OtherIdent, GetIdent mGet
| GetIdent mGet, OtherIdent ->
{
WithKeyword = mWith
GetKeyword = Some mGet
AndKeyword = mAnd
SetKeyword = None
}
| OtherIdent, SetIdent mSet
| SetIdent mSet, OtherIdent ->
{
WithKeyword = mWith
GetKeyword = None
AndKeyword = mAnd
SetKeyword = Some mSet
}
| _ ->
{
WithKeyword = mWith
AndKeyword = mAnd
GetKeyword = None
SetKeyword = None
}
{
WithKeyword = mWith
GetKeyword = Some mGet
AndKeyword = mAnd
SetKeyword = Some mSet
}
[ SynMemberDefn.GetSetMember(Some getBinding, Some setBinding, range, trivia) ]
| Some (SynMemberDefn.Member (binding, m), getOrSet), None

Просмотреть файл

@ -1,51 +0,0 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
namespace FSharp.Compiler.ComponentTests.Conformance.ClassTypes
open Xunit
open FSharp.Test.Compiler
module GetSetMembers =
[<Fact>]
let WithGetAndSet() =
Fsx """
type Foo() =
let mutable bar = ""
member this.Bar
with get () = bar
and set nextBar = bar <- nextBar
"""
|> withLangVersion50
|> typecheck
|> shouldSucceed
|> ignore
[<Fact>]
let WithGet() =
Fsx """
type Foo() =
let mutable bar = ""
member this.Bar
with get () = bar
"""
|> withLangVersion50
|> typecheck
|> shouldSucceed
|> ignore
[<Fact>]
let WithSet() =
Fsx """
type Foo() =
let mutable bar = ""
member this.Bar
with set nextBar = bar <- nextBar
"""
|> withLangVersion50
|> typecheck
|> shouldSucceed
|> ignore

Просмотреть файл

@ -32,7 +32,6 @@
<Compile Include="Conformance\ClassTypes\ExplicitObjectConstructors\ExplicitObjectConstructors.fs" />
<Compile Include="Conformance\ClassTypes\ImplicitObjectConstructors\ImplicitObjectConstructors.fs" />
<Compile Include="Conformance\ClassTypes\ValueRestriction\ValueRestriction.fs" />
<Compile Include="Conformance\ClassTypes\GetSetMembers\GetSetMembers.fs" />
<Compile Include="Conformance\DelegateTypes\DelegateDefinition.fs" />
<Compile Include="Conformance\DeclarationElements\AccessibilityAnnotations\Basic\Basic.fs" />
<Compile Include="Conformance\DeclarationElements\AccessibilityAnnotations\OnOverridesAndIFaceImpl\OnOverridesAndIFaceImpl.fs" />

Просмотреть файл

@ -785,6 +785,41 @@ type Foo =
assertRange (3, 4) (5, 54) m
| _ -> Assert.Fail "Could not get valid AST"
[<Test>]
let ``SynTypeDefn with member with set/get`` () =
let parseResults =
getParseResults
"""
type A() =
member this.Z with set (_:int):unit = () and get():int = 1
"""
match parseResults with
| ParsedInput.ImplFile (ParsedImplFileInput (modules = [ SynModuleOrNamespace.SynModuleOrNamespace(decls = [
SynModuleDecl.Types(
typeDefns = [ SynTypeDefn(typeRepr = SynTypeDefnRepr.ObjectModel(members = [
SynMemberDefn.ImplicitCtor _
SynMemberDefn.GetSetMember(Some (SynBinding(headPat = SynPat.LongIdent(extraId = Some getIdent))),
Some (SynBinding(headPat = SynPat.LongIdent(extraId = Some setIdent))),
m,
{ WithKeyword = mWith
GetKeyword = Some mGet
AndKeyword = Some mAnd
SetKeyword = Some mSet })
])) ]
)
]) ])) ->
Assert.AreEqual("get", getIdent.idText)
Assert.AreEqual("set", setIdent.idText)
assertRange (3, 18) (3, 22) mWith
assertRange (3, 23) (3, 26) mSet
assertRange (3, 23) (3, 26) setIdent.idRange
assertRange (3, 45) (3, 48) mAnd
assertRange (3, 49) (3, 52) mGet
assertRange (3, 49) (3, 52) getIdent.idRange
assertRange (3, 4) (3, 62) m
| _ -> Assert.Fail "Could not get valid AST"
module SyntaxExpressions =
[<Test>]
let ``SynExpr.Do contains the range of the do keyword`` () =