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

Merge main to release/dev17.12 #17525

Merged
merged 4 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions DEVGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,17 @@ or
> **Note**
> Please note, that by default, **Release** version of IL baseline tests will be running in CI, so when updating baseline (.bsl) files, make sure to add `-c Release` flag to the build command.


### Updating FCS surface area baselines

```bash
$env:TEST_UPDATE_BSL=1
dotnet test tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj --filter "SurfaceAreaTest" /p:BUILDING_USING_DOTNET=true
dotnet test tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj --filter "SurfaceAreaTest" /p:BUILDING_USING_DOTNET=true
dotnet test tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj --filter "SurfaceAreaTest" -c Release /p:BUILDING_USING_DOTNET=true
dotnet test tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj --filter "SurfaceAreaTest" -c Release /p:BUILDING_USING_DOTNET=true
```

## Automated Source Code Formatting

Some of the code in this repository is formatted automatically by [Fantomas](https://github.com/fsprojects/fantomas). To format all files use:
Expand Down
3 changes: 2 additions & 1 deletion docs/release-notes/.FSharp.Compiler.Service/9.0.100.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* Parser: recover on missing union case fields (PR [#17452](https://github.com/dotnet/fsharp/pull/17452))
* Parser: recover on missing union case field types (PR [#17455](https://github.com/dotnet/fsharp/pull/17455))
* Sink: report function domain type ([PR #17470](https://github.com/dotnet/fsharp/pull/17470))
* Allow access modifies to auto properties getters and setters ([PR 16687](https://github.com/dotnet/fsharp/pull/16687), [PR 16861](https://github.com/dotnet/fsharp/pull/16861), [Language suggestion #430](https://github.com/fsharp/fslang-suggestions/issues/430))
* 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))

### Changed
Expand All @@ -27,4 +27,5 @@
* Enforce `AttributeTargets` on unions. ([PR #17389](https://github.com/dotnet/fsharp/pull/17389))
* Ensure that isinteractive multi-emit backing fields are not public. ([Issue #17439](https://github.com/dotnet/fsharp/issues/17438)), ([PR #17439](https://github.com/dotnet/fsharp/pull/17439))
* Enable FSharp 9.0 Language Version ([Issue #17497](https://github.com/dotnet/fsharp/issues/17438)), [PR](https://github.com/dotnet/fsharp/pull/17500)))
* Better error reporting for unions with duplicated fields. ([PR #17521](https://github.com/dotnet/fsharp/pull/17521))
### Breaking Changes
2 changes: 1 addition & 1 deletion docs/release-notes/.Language/preview.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Bidirectional F#/C# interop for 'unmanaged' constraint. ([PR #12154](https://github.com/dotnet/fsharp/pull/12154))
* Make `.Is*` discriminated union properties visible. ([Language suggestion #222](https://github.com/fsharp/fslang-suggestions/issues/222), [PR #16341](https://github.com/dotnet/fsharp/pull/16341))
* Allow returning bool instead of unit option for partial active patterns. ([Language suggestion #1041](https://github.com/fsharp/fslang-suggestions/issues/1041), [PR #16473](https://github.com/dotnet/fsharp/pull/16473))
* Allow access modifies to auto properties getters and setters ([PR 16687](https://github.com/dotnet/fsharp/pull/16687), [PR 16861](https://github.com/dotnet/fsharp/pull/16861), [Language suggestion #430](https://github.com/fsharp/fslang-suggestions/issues/430))
* 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))
* 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))
Expand Down
18 changes: 13 additions & 5 deletions src/Compiler/Checking/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -500,18 +500,26 @@ module TcRecdUnionAndEnumDeclarations =
if not (String.isLeadingIdentifierCharacterUpperCase name) && name <> opNameCons && name <> opNameNil then
errorR(NotUpperCaseConstructor(id.idRange))

let ValidateFieldNames (synFields: SynField list, tastFields: RecdField list) =
let private CheckUnionDuplicateFields (elems: Ident list) =
elems |> List.iteri (fun i (uc1: Ident) ->
elems |> List.iteri (fun j (uc2: Ident) ->
if j > i && uc1.idText = uc2.idText then
errorR(Error(FSComp.SR.tcFieldNameIsUsedModeThanOnce(uc1.idText), uc1.idRange))))

let ValidateFieldNames (synFields: SynField list, tastFields: RecdField list) =
let fields = synFields |> List.choose (function SynField(idOpt = Some ident) -> Some ident | _ -> None)
if fields.Length > 1 then
CheckUnionDuplicateFields fields

let seen = Dictionary()
(synFields, tastFields) ||> List.iter2 (fun sf f ->
match seen.TryGetValue f.LogicalName with
| true, synField ->
match sf, synField with
| SynField(idOpt = Some id), SynField(idOpt = Some _) ->
error(Error(FSComp.SR.tcFieldNameIsUsedModeThanOnce(id.idText), id.idRange))
| SynField(idOpt = Some id), SynField(idOpt = None)
| SynField(idOpt = None), SynField(idOpt = Some id) ->
error(Error(FSComp.SR.tcFieldNameConflictsWithGeneratedNameForAnonymousField(id.idText), id.idRange))
| _ -> assert false
errorR(Error(FSComp.SR.tcFieldNameConflictsWithGeneratedNameForAnonymousField(id.idText), id.idRange))
| _ -> ()
| _ ->
seen.Add(f.LogicalName, sf))

Expand Down
8 changes: 4 additions & 4 deletions src/Compiler/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1771,10 +1771,10 @@ featureReuseSameFieldsInStructUnions,"Share underlying fields in a [<Struct>] di
3868,tcActivePatternArgsCountNotMatchOnlyPat,"This active pattern expects exactly one pattern argument, e.g., '%s pat'."
3868,tcActivePatternArgsCountNotMatchArgs,"This active pattern expects %d expression argument(s), e.g., '%s%s'."
3868,tcActivePatternArgsCountNotMatchArgsAndPat,"This active pattern expects %d expression argument(s) and a pattern argument, e.g., '%s%s pat'."
featureAllowAccessModifiersToAutoPropertiesGettersAndSetters,"Allow access modifiers to auto properties getters and setters"
3869,tcAccessModifiersNotAllowedInSRTPConstraint,"Access modifiers cannot be applied to an SRTP constraint."
featureParsedHashDirectiveArgumentNonString,"# directives with non-quoted string arguments"
3870,featureParsedHashDirectiveUnexpectedInteger,"Unexpected integer literal '%d'."
3870,featureParsedHashDirectiveUnexpectedIdentifier,"Unexpected identifier '%s'."
3869,featureParsedHashDirectiveUnexpectedInteger,"Unexpected integer literal '%d'."
3869,featureParsedHashDirectiveUnexpectedIdentifier,"Unexpected identifier '%s'."
featureEmptyBodiedComputationExpressions,"Support for computation expressions with empty bodies: builder {{ }}"
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."
2 changes: 1 addition & 1 deletion src/Compiler/SyntaxTree/SyntaxTree.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,7 @@ type SynComponentInfo =
/// Gets the syntax range of this construct
member Range: range

/// Represents two access
/// Represents one or two access modifier(s) in a property signature
[<NoEquality; NoComparison; RequireQualifiedAccess>]
type SynValSigAccess =
| Single of accessibility: SynAccess option
Expand Down
4 changes: 2 additions & 2 deletions src/FSharp.Core/option.fs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ module Option =
[<CompiledName("OfNullable")>]
let inline ofNullable (value: System.Nullable<'T>) =
if value.HasValue then
Some value.Value
Some (value.GetValueOrDefault())
else
None

Expand Down Expand Up @@ -338,7 +338,7 @@ module ValueOption =
[<CompiledName("OfNullable")>]
let inline ofNullable (value: System.Nullable<'T>) =
if value.HasValue then
ValueSome value.Value
ValueSome (value.GetValueOrDefault())
else
ValueNone

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@

exception AAA of Data1 : int * string

exception BBB of A : int * A : string
exception BBB of A : int * A : string

exception CCC of A : int * A : string * A : int
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,10 @@ module ExceptionDefinition =
|> compile
|> shouldFail
|> withDiagnostics [
(Error 3176, Line 6, Col 18, Line 6, Col 23, "Named field 'Data1' conflicts with autogenerated name for anonymous field.")
(Error 3176, Line 8, Col 28, Line 8, Col 29, "Named field 'A' is used more than once.")
(Error 3176, Line 6, Col 18, Line 6, Col 23, "Named field 'Data1' conflicts with autogenerated name for anonymous field.");
(Error 3176, Line 8, Col 18, Line 8, Col 19, "Named field 'A' is used more than once.");
(Error 3176, Line 10, Col 18, Line 10, Col 19, "Named field 'A' is used more than once.");
(Error 3176, Line 10, Col 28, Line 10, Col 29, "Named field 'A' is used more than once.")
]

// SOURCE=E_FieldNameUsedMulti.fs SCFLAGS="--test:ErrorRanges" # E_FieldNameUsedMulti.fs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1282,10 +1282,10 @@ let inline length4 (x: ^a when ^a: (member public get_Length: unit -> int)) = x.
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 3869, Line 2, Col 43, Line 2, Col 49, "Access modifiers cannot be applied to an SRTP constraint.")
(Error 3869, Line 3, Col 61, Line 3, Col 67, "Access modifiers cannot be applied to an SRTP constraint.")
(Error 3869, Line 4, Col 61, Line 4, Col 67, "Access modifiers cannot be applied to an SRTP constraint.")
(Error 3869, Line 5, Col 44, Line 5, Col 50, "Access modifiers cannot be applied to an SRTP constraint.")
(Error 3871, Line 2, Col 43, Line 2, Col 49, "Access modifiers cannot be applied to an SRTP constraint.")
(Error 3871, Line 3, Col 61, Line 3, Col 67, "Access modifiers cannot be applied to an SRTP constraint.")
(Error 3871, Line 4, Col 61, Line 4, Col 67, "Access modifiers cannot be applied to an SRTP constraint.")
(Error 3871, Line 5, Col 44, Line 5, Col 50, "Access modifiers cannot be applied to an SRTP constraint.")
]

[<Fact>]
Expand All @@ -1300,10 +1300,10 @@ let inline length4 (x: ^a when ^a: (member public get_Length: unit -> int)) = x.
|> typecheck
|> shouldFail
|> withDiagnostics [
(Warning 3869, Line 2, Col 43, Line 2, Col 49, "Access modifiers cannot be applied to an SRTP constraint.")
(Warning 3869, Line 3, Col 61, Line 3, Col 67, "Access modifiers cannot be applied to an SRTP constraint.")
(Warning 3869, Line 4, Col 61, Line 4, Col 67, "Access modifiers cannot be applied to an SRTP constraint.")
(Warning 3869, Line 5, Col 44, Line 5, Col 50, "Access modifiers cannot be applied to an SRTP constraint.")
(Warning 3871, Line 2, Col 43, Line 2, Col 49, "Access modifiers cannot be applied to an SRTP constraint.")
(Warning 3871, Line 3, Col 61, Line 3, Col 67, "Access modifiers cannot be applied to an SRTP constraint.")
(Warning 3871, Line 4, Col 61, Line 4, Col 67, "Access modifiers cannot be applied to an SRTP constraint.")
(Warning 3871, Line 5, Col 44, Line 5, Col 50, "Access modifiers cannot be applied to an SRTP constraint.")
]

[<FactForNETCOREAPP>]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ type MyDU =
| Case1 of Item2 : int * string

type MyDU2 =
| Case1 of A : int * A : string
| Case1 of A : int * A : string * A : int
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,9 @@ type StructUnion =
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 3176, Line 5, Col 27, Line 5, Col 31, "Named field 'item' is used more than once.")
(Error 3176, Line 5, Col 12, Line 5, Col 16, "Named field 'item' is used more than once.");
(Error 3585, Line 5, Col 12, Line 5, Col 16, "If a multicase union type is a struct, then all fields with the same name must be of the same type. This rule applies also to the generated 'Item' name in case of unnamed fields.");
(Error 3585, Line 5, Col 27, Line 5, Col 31, "If a multicase union type is a struct, then all fields with the same name must be of the same type. This rule applies also to the generated 'Item' name in case of unnamed fields.")
]

[<Fact>]
Expand All @@ -417,7 +419,10 @@ type StructUnion =
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 3176, Line 5, Col 27, Line 5, Col 31, "Named field 'Item' is used more than once.")
(Error 3176, Line 5, Col 12, Line 5, Col 16, "Named field 'Item' is used more than once.");
(Error 3585, Line 5, Col 12, Line 5, Col 16, "If a multicase union type is a struct, then all fields with the same name must be of the same type. This rule applies also to the generated 'Item' name in case of unnamed fields.");
(Error 3585, Line 5, Col 27, Line 5, Col 31, "If a multicase union type is a struct, then all fields with the same name must be of the same type. This rule applies also to the generated 'Item' name in case of unnamed fields.");
(Error 3585, Line 6, Col 12, Line 6, Col 18, "If a multicase union type is a struct, then all fields with the same name must be of the same type. This rule applies also to the generated 'Item' name in case of unnamed fields.")
]

[<Fact>]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ module UnionTypes =
|> verifyCompile
|> shouldFail
|> withDiagnostics [
(Error 3176, Line 7, Col 16, Line 7, Col 21, "Named field 'Item2' conflicts with autogenerated name for anonymous field.")
(Error 3176, Line 7, Col 16, Line 7, Col 21, "Named field 'Item2' conflicts with autogenerated name for anonymous field.");
(Error 3176, Line 10, Col 16, Line 10, Col 17, "Named field 'A' is used more than once.");
(Error 3176, Line 10, Col 26, Line 10, Col 27, "Named field 'A' is used more than once.")
]

Expand Down Expand Up @@ -750,3 +751,59 @@ type MyId =
(Error 23, Line 7, Col 17, Line 7, Col 20, "The member 'IdA' can not be defined because the name 'IdA' clashes with the union case 'IdA' in this type or module")
(Error 23, Line 17, Col 17, Line 17, Col 20, "The member 'IdC' can not be defined because the name 'IdC' clashes with the union case 'IdC' in this type or module")
]


[<Fact>]
let ``Union field appears multiple times in union declaration`` () =
Fsx """
type X =
| A of a: int * a: int
"""
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 3176, Line 3, Col 12, Line 3, Col 13, "Named field 'a' is used more than once.")
]

[<Fact>]
let ``Union field appears multiple times in union declaration 2`` () =
Fsx """
type X =
| A of a: int * a: int
| B of a: int * a: int
"""
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 3176, Line 3, Col 12, Line 3, Col 13, "Named field 'a' is used more than once.")
(Error 3176, Line 4, Col 12, Line 4, Col 13, "Named field 'a' is used more than once.")
]

[<Fact>]
let ``Union field appears multiple times in union declaration 3`` () =
Fsx """
type X =
| A of a: int * a: int * a: int
"""
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 3176, Line 3, Col 12, Line 3, Col 13, "Named field 'a' is used more than once.")
(Error 3176, Line 3, Col 21, Line 3, Col 22, "Named field 'a' is used more than once.")
]

[<Fact>]
let ``Union field appears multiple times in union declaration 4`` () =
Fsx """
type X =
| A of a: int * a: int
let x = A (1, 2)
match x with
| A(a = 1) -> ()
| _ -> ()
"""
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 3176, Line 3, Col 12, Line 3, Col 13, "Named field 'a' is used more than once.")
]
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,10 @@ printfn "Hello, World"
|> asExe
|> compile
|> shouldFail
|> withDiagnostics[
|> withDiagnostics [
(Warning 3353, Line 2, Col 9, Line 2, Col 11, "Invalid directive '#r '")
(Warning 213, Line 3, Col 9, Line 3, Col 14, "'' is not a valid assembly name")
(Error 3870, Line 4, Col 12, Line 4, Col 17, "Unexpected identifier 'Ident'.")
(Error 3870, Line 5, Col 12, Line 5, Col 22, "Unexpected identifier 'Long.Ident'.")
(Error 3870, Line 6, Col 12, Line 6, Col 15, "Unexpected integer literal '123'.")
]
(Error 3869, Line 4, Col 12, Line 4, Col 17, "Unexpected identifier 'Ident'.")
(Error 3869, Line 5, Col 12, Line 5, Col 22, "Unexpected identifier 'Long.Ident'.")
(Error 3869, Line 6, Col 12, Line 6, Col 15, "Unexpected integer literal '123'.")
]
Loading