diff --git a/DEVGUIDE.md b/DEVGUIDE.md index 9e0fbb2cd3f..4cac14d45f3 100644 --- a/DEVGUIDE.md +++ b/DEVGUIDE.md @@ -128,8 +128,11 @@ If your changes involve modifying the list of language keywords in any way, (e.g ```shell dotnet build src\Compiler /t:UpdateXlf ``` +If you are on a Mac, you can run this command from the root of the repository: -This only works on Windows/.NETStandard framework, so changing this from any other platform requires editing and syncing all of the XLF files manually. +```shell +sh build.sh -c Release +``` ## Updating baselines in tests diff --git a/src/Compiler/Checking/CheckDeclarations.fs b/src/Compiler/Checking/CheckDeclarations.fs index 0086fb44d2f..59548d96e06 100644 --- a/src/Compiler/Checking/CheckDeclarations.fs +++ b/src/Compiler/Checking/CheckDeclarations.fs @@ -3985,7 +3985,13 @@ module EstablishTypeDefinitionCores = match fields' with | rf :: _ -> errorR (Error(FSComp.SR.tcInterfaceTypesAndDelegatesCannotContainFields(), rf.Range)) | _ -> () - + + let primaryConstructorInDelegateCheck(implicitCtorSynPats : SynSimplePats option) = + match implicitCtorSynPats with + | None -> () + | Some spats -> + let ctorArgNames, _ = TcSimplePatsOfUnknownType cenv true CheckCxs envinner tpenv spats + if not ctorArgNames.IsEmpty then errorR (Error(FSComp.SR.parsOnlyClassCanTakeValueArguments(), m)) let envinner = AddDeclaredTypars CheckForDuplicateTypars (tycon.Typars m) envinner let envinner = MakeInnerEnvForTyconRef envinner thisTyconRef false @@ -4182,6 +4188,7 @@ module EstablishTypeDefinitionCores = noAllowNullLiteralAttributeCheck() noAbstractClassAttributeCheck() noFieldsCheck userFields + primaryConstructorInDelegateCheck(implicitCtorSynPats) let tyR, _ = TcTypeAndRecover cenv NoNewTypars CheckCxs ItemOccurence.UseInType envinner tpenv ty let _, _, curriedArgInfos, returnTy, _ = GetTopValTypeInCompiledForm g (arity |> TranslateSynValInfo m (TcAttributes cenv envinner) |> TranslatePartialValReprInfo []) 0 tyR m if curriedArgInfos.Length < 1 then error(Error(FSComp.SR.tcInvalidDelegateSpecification(), m)) diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/DelegateTypes/DelegateDefinition.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/DelegateTypes/DelegateDefinition.fs new file mode 100644 index 00000000000..df0857b3f28 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/DelegateTypes/DelegateDefinition.fs @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace FSharp.Compiler.ComponentTests.Conformance.DelegateTypes + +open Xunit +open FSharp.Test.Compiler + +module DelegateDefinition = + + [] + let ``Delegate definition with primary constructor and argument.`` () = + FSharp + """ +namespace FSharpTest + type T(x: int) = + delegate of int -> int + """ + |> compile + |> shouldFail + |> withErrorCode 552 + |> withErrorMessage "Only class types may take value arguments" + + [] + let ``Delegate definition with primary constructor no argument.`` () = + FSharp + """ +namespace FSharpTest + type T() = + delegate of int -> int + """ + |> compile + |> shouldFail + |> withErrorCode 552 + |> withErrorMessage "Only class types may take value arguments" + + [] + let ``Delegate definition`` () = + FSharp + """ +namespace FSharpTest + type T = + delegate of int -> int + """ + |> compile + |> shouldSucceed diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/DelegateTypes/invalid_delegate_definition.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/DelegateTypes/invalid_delegate_definition.fs new file mode 100644 index 00000000000..dd55759ff61 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/DelegateTypes/invalid_delegate_definition.fs @@ -0,0 +1,5 @@ +type T(x: int) = + delegate of int -> int + +type T() = + delegate of int -> int \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/DelegateTypes/invalid_delegate_definition.fs.err.bsl b/tests/FSharp.Compiler.ComponentTests/Conformance/DelegateTypes/invalid_delegate_definition.fs.err.bsl new file mode 100644 index 00000000000..c804d430211 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/DelegateTypes/invalid_delegate_definition.fs.err.bsl @@ -0,0 +1,3 @@ +invalid_delegate_definition.fs (1,6)-(1,15) Only class types may take value arguments +invalid_delegate_definition.fs (4,6)-(1,9) Only class types may take value arguments + diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index a91bb7b00a2..60899840d4e 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -38,6 +38,7 @@ + diff --git a/tests/fsharp/typecheck/sigs/neg06.fs b/tests/fsharp/typecheck/sigs/neg06.fs index a31bbbba21c..ee9ddce60dc 100644 --- a/tests/fsharp/typecheck/sigs/neg06.fs +++ b/tests/fsharp/typecheck/sigs/neg06.fs @@ -24,7 +24,7 @@ type BadSealedInterface = type BadSealedAbbreviatedType = System.Object [] -type UnnecessarilySealedDelegate() = delegate of int -> int +type UnnecessarilySealedDelegate = delegate of int -> int type BadExtensionOfSealedType() = class diff --git a/tests/fsharpqa/Source/Conformance/ObjectOrientedTypeDefinitions/DelegateTypes/env.lst b/tests/fsharpqa/Source/Conformance/ObjectOrientedTypeDefinitions/DelegateTypes/env.lst index bb9e0f2ae1f..e805eea233c 100644 --- a/tests/fsharpqa/Source/Conformance/ObjectOrientedTypeDefinitions/DelegateTypes/env.lst +++ b/tests/fsharpqa/Source/Conformance/ObjectOrientedTypeDefinitions/DelegateTypes/env.lst @@ -1,10 +1,9 @@ SOURCE=ByrefArguments01.fs # ByrefArguments01.fs SOURCE=E_InvalidSignature01.fs # E_InvalidSignature01.fs SOURCE=E_InvalidSignature02.fs # E_InvalidSignature02.fs - SOURCE=ValidSignature_MultiArg01.fs # ValidSignature_MultiArg01.fs SOURCE=ValidSignature_ReturningValues01.fs # ValidSignature_ReturningValues01.fs # This test has a dependency on NetFx3.5 (i.e. CSC_PIPE must be 3.5 or better) # For this reason, we exclude it from MT -NoMT SOURCE=DelegateBindingInvoke01.fs PRECMD="\$CSC_PIPE /t:library IDelegateBinding.cs" SCFLAGS="-r:IDelegateBinding.dll" # DelegateBindingInvoke01.fs \ No newline at end of file +NoMT SOURCE=DelegateBindingInvoke01.fs PRECMD="\$CSC_PIPE /t:library IDelegateBinding.cs" SCFLAGS="-r:IDelegateBinding.dll" # DelegateBindingInvoke01.fs