Merge pull request #17617 from dotnet/merges/main-to-release/dev17.12

This commit is contained in:
Vlad Zarytovskii 2024-08-27 19:13:58 +02:00 коммит произвёл GitHub
Родитель 2b02b7d065 309b42c5b9
Коммит a5feb41907
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
22 изменённых файлов: 331 добавлений и 30 удалений

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

@ -1,5 +1,9 @@
# Because this repository uses squash/rebase merges, commits added to a branch
# referencing earlier commits in the same branch and squash/rebased merged as part of a PR
# will need to be rewritten in a subsequent PR to the corresponding squashed/rebased commit SHAs.
# Format src/Compiler/Checking/CheckComputationExpressions.fs, https://github.com/dotnet/fsharp/pull/16512
603a310cdfd9902ec1d29b399377dcc9ac56235b
0318afd91f38533879cc89d598e0431c312ad57e
# Spelling, https://github.com/dotnet/fsharp/pull/16212
823d5e99fdd13f696ea8fe572d502e5fa68f6fd1
23e91e1322363a7e9c34baaeabbf0391c4b7eafd

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

@ -7,6 +7,7 @@
<RepoRoot Condition="'$(RepoRoot)' == ''">$(MSBuildThisFileDirectory)</RepoRoot>
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>
<FSharpNetCoreProductDefaultTargetFramework>net9.0</FSharpNetCoreProductDefaultTargetFramework>
<IgnoreMibc Condition="'$(IgnoreMibc)' == ''">$(DotNetBuildFromSource)</IgnoreMibc>
</PropertyGroup>
<!--

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

@ -37,4 +37,19 @@
</KnownCrossgen2Pack>
</ItemGroup>
<!-- We want to restore ALL the MIBCs when we build anything, since in the future it will contain different profiles, not only the FSC one we got from building Giraffe -->
<Import Project="$(MSBuildThisFileDirectory)\eng\restore\optimizationData.targets"/>
<ItemGroup>
<PackageReference Include="@(MIBCPackage)" />
</ItemGroup>
<Target Name="CopyMIBCWrapper" AfterTargets="Restore" BeforeTargets="Build;Pack">
<MSBuild
Projects="$(MSBuildThisFileDirectory)eng\restore\optimizationData.targets"
Properties="ArtifactsDir=$(MSBuildThisFileDirectory)artifacts\;NuGetPackageRoot=$(NuGetPackageRoot);MibcFiles=$(MibcFiles);optimizationwindows_ntx86MIBCRuntimeVersion=$(optimizationwindows_ntx86MIBCRuntimeVersion);optimizationwindows_ntx64MIBCRuntimeVersion=$(optimizationwindows_ntx64MIBCRuntimeVersion);optimizationwindows_ntarm64MIBCRuntimeVersion=$(optimizationwindows_ntarm64MIBCRuntimeVersion);optimizationlinuxx64MIBCRuntimeVersion=$(optimizationlinuxx64MIBCRuntimeVersion);optimizationlinuxarm64MIBCRuntimeVersion=$(optimizationlinuxarm64MIBCRuntimeVersion)"
Targets="CopyMIBC"
RemoveProperties="TargetFramework"
StopOnFirstFailure="True" />
</Target>
</Project>

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

@ -0,0 +1,27 @@
<Project>
<!-- We want to restore ALL the MIBCs when we build anything, since in the future it will contain different profiles, not only the FSC one we got from building Giraffe -->
<ItemGroup Condition="'$(IgnoreMIBC)' != 'true'">
<MIBCPackage Include="optimization.windows_nt-x86.mibc.runtime" Version="$(optimizationwindows_ntx86MIBCRuntimeVersion)" />
<MIBCPackage Include="optimization.windows_nt-x64.mibc.runtime" Version="$(optimizationwindows_ntx64MIBCRuntimeVersion)" />
<MIBCPackage Include="optimization.windows_nt-arm64.mibc.runtime" Version="$(optimizationwindows_ntarm64MIBCRuntimeVersion)" />
<MIBCPackage Include="optimization.linux-x64.mibc.runtime" Version="$(optimizationlinuxx64MIBCRuntimeVersion)" />
<MIBCPackage Include="optimization.linux-arm64.mibc.runtime" Version="$(optimizationlinuxarm64MIBCRuntimeVersion)" />
</ItemGroup>
<!-- We copy all packages to the output (per architecture) -->
<Target Name="CopyMIBC">
<ItemGroup>
<MibcFiles Include="$(NuGetPackageRoot)%(MibcPackage.Identity)\%(MibcPackage.Version)\**\DotNet_FSharp.mibc" />
</ItemGroup>
<Copy
SourceFiles="@(MibcFiles)"
DestinationFolder="$(ArtifactsDir)mibc\%(MibcPackage.Identity)\"
SkipUnchangedFiles="true" />
<Copy
SourceFiles="@(MibcFiles)"
DestinationFolder="$(ArtifactsDir)mibc-proto\%(MibcPackage.Identity)\"
SkipUnchangedFiles="true" />
</Target>
</Project>

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

@ -2856,12 +2856,16 @@ module EstablishTypeDefinitionCores =
let hasStructAttr = HasFSharpAttribute g g.attrib_StructAttribute attrs
let hasCLIMutable = HasFSharpAttribute g g.attrib_CLIMutableAttribute attrs
let hasAllowNullLiteralAttr = HasFSharpAttribute g g.attrib_AllowNullLiteralAttribute attrs
let hasSealedAttr = HasFSharpAttribute g g.attrib_SealedAttribute attrs
let structLayoutAttr = HasFSharpAttribute g g.attrib_StructLayoutAttribute attrs
// We want to keep these special attributes treatment and avoid having two errors for the same attribute.
let reportAttributeTargetsErrors =
g.langVersion.SupportsFeature(LanguageFeature.EnforceAttributeTargets)
&& not hasCLIMutable // CLIMutableAttribute has a special treatment(specific error FS3132)
&& not hasAllowNullLiteralAttr // AllowNullLiteralAttribute has a special treatment(specific errors FS0934, FS093)
&& not hasSealedAttr // SealedAttribute has a special treatment(specific error FS942)
&& not structLayoutAttr // StructLayoutAttribute has a special treatment(specific error FS0937)
let noCLIMutableAttributeCheck() =
if hasCLIMutable then errorR (Error(FSComp.SR.tcThisTypeMayNotHaveACLIMutableAttribute(), m))

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

@ -11086,7 +11086,11 @@ and TcNormalizedBinding declKind (cenv: cenv) env tpenv overallTy safeThisValOpt
if not (isNil declaredTypars) then
errorR(Error(FSComp.SR.tcLiteralCannotHaveGenericParameters(), mBinding))
if g.langVersion.SupportsFeature(LanguageFeature.EnforceAttributeTargets) && memberFlagsOpt.IsNone && not attrs.IsEmpty then
let supportEnforceAttributeTargets =
(g.langVersion.SupportsFeature(LanguageFeature.EnforceAttributeTargets) && memberFlagsOpt.IsNone && not attrs.IsEmpty)
&& not isVolatile // // VolatileFieldAttribute has a special treatment(specific error FS823)
if supportEnforceAttributeTargets then
TcAttributeTargetsOnLetBindings { cenv with tcSink = TcResultsSink.NoSink } env attrs overallPatTy overallExprTy (not declaredTypars.IsEmpty) isClassLetBinding
CheckedBindingInfo(inlineFlag, valAttribs, xmlDoc, tcPatPhase2, explicitTyparInfo, nameToPrelimValSchemeMap, rhsExprChecked, argAndRetAttribs, overallPatTy, mBinding, debugPoint, isCompGen, literalValue, isFixed), tpenv
@ -11114,7 +11118,7 @@ and TcAttributeTargetsOnLetBindings (cenv: cenv) env attrs overallPatTy overallE
else
AttributeTargets.ReturnValue ||| AttributeTargets.Field ||| AttributeTargets.Property
TcAttributes cenv env attrTgt attrs |> ignore
TcAttributesWithPossibleTargets false cenv env attrTgt attrs |> ignore
and TcLiteral (cenv: cenv) overallTy env tpenv (attrs, synLiteralValExpr) =

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

@ -2044,6 +2044,7 @@ type FormattedDiagnosticDetailedInfo =
Location: FormattedDiagnosticLocation option
Canonical: FormattedDiagnosticCanonicalInformation
Message: string
Context: string option
}
[<RequireQualifiedAccess>]
@ -2051,7 +2052,7 @@ type FormattedDiagnostic =
| Short of FSharpDiagnosticSeverity * string
| Long of FSharpDiagnosticSeverity * FormattedDiagnosticDetailedInfo
let FormatDiagnosticLocation (tcConfig: TcConfig) m : FormattedDiagnosticLocation =
let FormatDiagnosticLocation (tcConfig: TcConfig) (m: Range) : FormattedDiagnosticLocation =
if equals m rangeStartup || equals m rangeCmdArgs then
{
Range = m
@ -2114,6 +2115,10 @@ let FormatDiagnosticLocation (tcConfig: TcConfig) m : FormattedDiagnosticLocatio
sprintf "%s(%d,%d,%d,%d): " file m.StartLine m.StartColumn m.EndLine m.EndColumn, m, file
else
"", m, file
| DiagnosticStyle.Rich ->
let file = file.Replace('/', Path.DirectorySeparatorChar)
let m = withStart (mkPos m.StartLine (m.StartColumn + 1)) m
(sprintf "◦→ %s (%d,%d)" file m.StartLine m.StartColumn), m, file
{
Range = m
@ -2154,8 +2159,12 @@ let CollectFormattedDiagnostics (tcConfig: TcConfig, severity: FSharpDiagnosticS
let text =
match tcConfig.diagnosticStyle with
// Show the subcategory for --vserrors so that we can fish it out in Visual Studio and use it to determine error stickiness.
| DiagnosticStyle.Emacs
| DiagnosticStyle.Gcc
| DiagnosticStyle.Default
| DiagnosticStyle.Test -> sprintf "%s FS%04d: " message errorNumber
| DiagnosticStyle.VisualStudio -> sprintf "%s %s FS%04d: " subcategory message errorNumber
| _ -> sprintf "%s FS%04d: " message errorNumber
| DiagnosticStyle.Rich -> sprintf "\n◦→ %s FS%04d: " message errorNumber
let canonical: FormattedDiagnosticCanonicalInformation =
{
@ -2164,11 +2173,51 @@ let CollectFormattedDiagnostics (tcConfig: TcConfig, severity: FSharpDiagnosticS
TextRepresentation = text
}
let message = diagnostic.FormatCore(tcConfig.flatErrors, suggestNames)
let message =
match tcConfig.diagnosticStyle with
| DiagnosticStyle.Emacs
| DiagnosticStyle.Gcc
| DiagnosticStyle.Default
| DiagnosticStyle.Test
| DiagnosticStyle.VisualStudio -> diagnostic.FormatCore(tcConfig.flatErrors, suggestNames)
| DiagnosticStyle.Rich ->
diagnostic.FormatCore(tcConfig.flatErrors, suggestNames).Split([| '\n' |])
|> Array.map (fun msg -> "\n◦ " + msg)
|> String.Concat
let context =
match tcConfig.diagnosticStyle with
| DiagnosticStyle.Emacs
| DiagnosticStyle.Gcc
| DiagnosticStyle.Default
| DiagnosticStyle.Test
| DiagnosticStyle.VisualStudio -> None
| DiagnosticStyle.Rich ->
match diagnostic.Range with
| Some m ->
let content =
m.FileName
|> FileSystem.GetFullFilePathInDirectoryShim tcConfig.implicitIncludeDir
|> System.IO.File.ReadAllLines
if m.StartLine = m.EndLine then
$"\n◦ {m.StartLine} |{content[m.StartLine - 1]}\n"
+ $"""◦ {String.init (m.StartColumn + 3) (fun _ -> " ")}^{String.init (m.EndColumn - m.StartColumn) (fun _ -> "~")}"""
|> Some
else
content
|> fun lines -> Array.sub lines (m.StartLine - 1) (m.EndLine - m.StartLine - 1)
|> Array.fold
(fun (context, lineNumber) line -> (context + $"\n◦ {lineNumber} |{line}", lineNumber + 1))
("", (m.StartLine))
|> fst
|> Some
| None -> None
let entry: FormattedDiagnosticDetailedInfo =
{
Location = where
Context = context
Canonical = canonical
Message = message
}
@ -2199,7 +2248,11 @@ type PhasedDiagnostic with
| FormattedDiagnostic.Short(_, txt) -> buf.AppendString txt
| FormattedDiagnostic.Long(_, details) ->
match details.Location with
| Some l when not l.IsEmpty -> buf.AppendString l.TextRepresentation
| Some l when not l.IsEmpty ->
buf.AppendString l.TextRepresentation
// Because details.Context depends on the value of details.Location, if details.Location is not None, details.Context can be accessed directly.
if details.Context.IsSome then
buf.AppendString details.Context.Value
| _ -> ()
buf.AppendString details.Canonical.TextRepresentation

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

@ -113,7 +113,8 @@ type FormattedDiagnosticCanonicalInformation =
type FormattedDiagnosticDetailedInfo =
{ Location: FormattedDiagnosticLocation option
Canonical: FormattedDiagnosticCanonicalInformation
Message: string }
Message: string
Context: string option }
/// Used internally and in LegacyHostedCompilerForTesting
[<RequireQualifiedAccess>]

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

@ -18,13 +18,14 @@ open Internal.Utilities.Library.Extras
open System.Threading.Tasks
/// Represents the style being used to format errors
[<RequireQualifiedAccess>]
[<RequireQualifiedAccess; NoComparison; NoEquality>]
type DiagnosticStyle =
| Default
| Emacs
| Test
| VisualStudio
| Gcc
| Rich
/// Thrown when we want to add some range information to a .NET exception
exception WrappedError of exn * range with

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

@ -10,13 +10,14 @@ open System.Runtime.CompilerServices
open System.Runtime.InteropServices
/// Represents the style being used to format errors
[<RequireQualifiedAccess>]
[<RequireQualifiedAccess; NoComparison; NoEquality>]
type DiagnosticStyle =
| Default
| Emacs
| Test
| VisualStudio
| Gcc
| Rich
/// Thrown when we want to add some range information to a .NET exception
exception WrappedError of exn * range

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

@ -28,6 +28,10 @@
<NuspecProperty Include="configuration=$(Configuration)" />
</ItemGroup>
<ItemGroup Condition="'$(IgnoreMibc)' != 'true'">
<NuspecProperty Include="mibcRoot=$(ArtifactsDir)\mibc" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(MSBuildThisFileDirectory)..\fsi\fsiProject\fsi.fsproj" />
<ProjectReference Include="$(MSBuildThisFileDirectory)..\fsc\fscProject\fsc.fsproj" />

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

@ -44,6 +44,9 @@
<file src="FSharp.Build\$configuration$\netstandard2.0\Microsoft.FSharp.NetSdk.targets" target="contentFiles\any\any" />
<file src="FSharp.Build\$configuration$\netstandard2.0\Microsoft.FSharp.Overrides.NetSdk.targets" target="contentFiles\any\any" />
<!-- PGO, MIBC -->
<file src="$mibcRoot$\**\*.mibc" target="contentFiles\mibc" />
<!-- resources -->
<file src="FSharp.Core\$configuration$\netstandard2.0\**\FSharp.Core.resources.dll"
target="lib\$fSharpNetCoreProductTargetFramework$" />

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

@ -9,9 +9,18 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Proto'">
<MibcTargetOS>linux</MibcTargetOS>
<!-- We deliberately want to use linux mibc pgo data on macOS -->
<MibcTargetOS Condition="$([MSBuild]::IsOSPlatform('OSX'))">linux</MibcTargetOS>
<MibcTargetOS Condition="$([MSBuild]::IsOSPlatform('WINDOWS'))">windows_nt</MibcTargetOS>
<MibcTargetArchitecture>$([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture.ToString().ToLowerInvariant)</MibcTargetArchitecture>
<MibcCurrentMachineArcitecture>$(MibcTargetOS)-$(MibcTargetArchitecture)</MibcCurrentMachineArcitecture>
<MibcFile>$(ArtifactsDir)mibc-proto\optimization.$(MibcCurrentMachineArcitecture).mibc.runtime\DotNet_FSharp.mibc</MibcFile>
<TargetFramework>$(FSharpNetCoreProductTargetFramework)</TargetFramework>
<PublishReadyToRun>$(EnablePublishReadyToRun)</PublishReadyToRun>
<RuntimeIdentifier>$(NETCoreSdkRuntimeIdentifier)</RuntimeIdentifier>
<ReadyToRunOptimizationData>$(MibcFile)</ReadyToRunOptimizationData>
</PropertyGroup>
<ItemGroup Condition="'$(Configuration)' == 'Proto'">
@ -24,6 +33,10 @@
<IntermediateOutputPath>$(ArtifactsDir)obj/$(MSBuildProjectName)/$(Configuration)/</IntermediateOutputPath>
</PropertyGroup>
<Target Name="ValidateMibcFile" AfterTargets="CopyMIBC" BeforeTargets="Build;Pack" Condition="'$(IgnoreMibc)' != 'true'">
<Error Condition="'$(Configuration)' == 'Proto' AND !Exists('$(MibcFile)')" Text="Mibc file '$(MibcFile)' does not exist." />
</Target>
<Import Project="$([MSBuild]::GetPathOfFileAbove('fsc.targets', '$(MSBuildThisFileDirectory)../'))" />
</Project>

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

@ -790,4 +790,116 @@ type InterruptibleLazy<'T> private (valueFactory: unit -> 'T) =
compilation
|> withLangVersionPreview
|> verifyCompile
|> shouldSucceed
|> shouldSucceed
// SOURCE= E_VolatileField.fs # E_VolatileField.fs
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"E_VolatileField.fs"|])>]
let ``E_VolatileField 9.0`` compilation =
compilation
|> withLangVersion90
|> verifyCompile
|> shouldFail
|> withDiagnostics [
(Error 823, Line 3, Col 3, Line 4, Col 16, "The 'VolatileField' attribute may only be used on 'let' bindings in classes")
(Error 823, Line 6, Col 3, Line 7, Col 14, "The 'VolatileField' attribute may only be used on 'let' bindings in classes")
(Error 879, Line 6, Col 3, Line 7, Col 14, "Volatile fields must be marked 'mutable' and cannot be thread-static")
(Error 823, Line 9, Col 3, Line 10, Col 9, "The 'VolatileField' attribute may only be used on 'let' bindings in classes")
(Error 879, Line 9, Col 3, Line 10, Col 9, "Volatile fields must be marked 'mutable' and cannot be thread-static")
(Error 823, Line 26, Col 17, Line 26, Col 18, "The 'VolatileField' attribute may only be used on 'let' bindings in classes")
(Error 879, Line 13, Col 5, Line 14, Col 19, "Volatile fields must be marked 'mutable' and cannot be thread-static")
(Error 879, Line 16, Col 5, Line 17, Col 20, "Volatile fields must be marked 'mutable' and cannot be thread-static")
(Error 879, Line 19, Col 5, Line 20, Col 11, "Volatile fields must be marked 'mutable' and cannot be thread-static")
(Error 879, Line 22, Col 5, Line 23, Col 13, "Volatile fields must be marked 'mutable' and cannot be thread-static")
]
// SOURCE=E_VolatileField.fs # E_VolatileField.fs
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"E_VolatileField.fs"|])>]
let ``E_VolatileField preview`` compilation =
compilation
|> withLangVersionPreview
|> verifyCompile
|> shouldFail
|> withDiagnostics [
(Error 823, Line 3, Col 3, Line 4, Col 16, "The 'VolatileField' attribute may only be used on 'let' bindings in classes")
(Error 823, Line 6, Col 3, Line 7, Col 14, "The 'VolatileField' attribute may only be used on 'let' bindings in classes")
(Error 879, Line 6, Col 3, Line 7, Col 14, "Volatile fields must be marked 'mutable' and cannot be thread-static")
(Error 823, Line 9, Col 3, Line 10, Col 9, "The 'VolatileField' attribute may only be used on 'let' bindings in classes")
(Error 879, Line 9, Col 3, Line 10, Col 9, "Volatile fields must be marked 'mutable' and cannot be thread-static")
(Error 823, Line 26, Col 17, Line 26, Col 18, "The 'VolatileField' attribute may only be used on 'let' bindings in classes")
(Error 879, Line 13, Col 5, Line 14, Col 19, "Volatile fields must be marked 'mutable' and cannot be thread-static")
(Error 879, Line 16, Col 5, Line 17, Col 20, "Volatile fields must be marked 'mutable' and cannot be thread-static")
(Error 879, Line 19, Col 5, Line 20, Col 11, "Volatile fields must be marked 'mutable' and cannot be thread-static")
(Error 879, Line 22, Col 5, Line 23, Col 13, "Volatile fields must be marked 'mutable' and cannot be thread-static")
]
// SOURCE= VolatileField01.fs # VolatileField01.fs
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"VolatileField01.fs"|])>]
let ``VolatileField01 9.0`` compilation =
compilation
|> withLangVersion90
|> verifyCompile
|> shouldSucceed
// SOURCE=VolatileField01.fs # VolatileField01.fs
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"VolatileField01.fs"|])>]
let ``VolatileField01 preview`` compilation =
compilation
|> withLangVersionPreview
|> verifyCompile
|> shouldSucceed
// SOURCE= E_SealedAttribute01.fs # E_SealedAttribute01.fs
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"E_SealedAttribute01.fs"|])>]
let ``E_SealedAttribute01 9.0`` compilation =
compilation
|> withLangVersion90
|> verifyCompile
|> shouldFail
|> withDiagnostics [
(Error 942, Line 2, Col 6, Line 2, Col 31, "Struct types are always sealed")
(Error 948, Line 8, Col 6, Line 8, Col 24, "Interface types cannot be sealed")
(Error 942, Line 14, Col 6, Line 14, Col 33, "Delegate types are always sealed")
]
// SOURCE=E_SealedAttribute01.fs # E_SealedAttribute01.fs
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"E_SealedAttribute01.fs"|])>]
let ``E_SealedAttribute01 preview`` compilation =
compilation
|> withLangVersionPreview
|> verifyCompile
|> shouldFail
|> withDiagnostics [
(Error 942, Line 2, Col 6, Line 2, Col 31, "Struct types are always sealed")
(Error 948, Line 8, Col 6, Line 8, Col 24, "Interface types cannot be sealed")
(Error 942, Line 14, Col 6, Line 14, Col 33, "Delegate types are always sealed")
]
// SOURCE= E_StructLayout01.fs # E_StructLayout01.fs
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"E_StructLayout01.fs"|])>]
let ``E_StructLayout01 9.0`` compilation =
compilation
|> withLangVersion90
|> verifyCompile
|> shouldFail
|> withDiagnostics [
(Error 937, Line 2, Col 6, Line 2, Col 8, "Only structs and classes without primary constructors may be given the 'StructLayout' attribute")
(Error 937, Line 7, Col 6, Line 7, Col 8, "Only structs and classes without primary constructors may be given the 'StructLayout' attribute")
(Error 937, Line 11, Col 6, Line 11, Col 8, "Only structs and classes without primary constructors may be given the 'StructLayout' attribute")
(Error 937, Line 14, Col 6, Line 14, Col 8, "Only structs and classes without primary constructors may be given the 'StructLayout' attribute")
(Error 937, Line 17, Col 6, Line 17, Col 8, "Only structs and classes without primary constructors may be given the 'StructLayout' attribute")
]
// SOURCE=E_StructLayout01.fs # E_StructLayout01.fs
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"E_StructLayout01.fs"|])>]
let ``E_StructLayout01 preview`` compilation =
compilation
|> withLangVersionPreview
|> verifyCompile
|> shouldFail
|> withDiagnostics [
(Error 937, Line 2, Col 6, Line 2, Col 8, "Only structs and classes without primary constructors may be given the 'StructLayout' attribute")
(Error 937, Line 7, Col 6, Line 7, Col 8, "Only structs and classes without primary constructors may be given the 'StructLayout' attribute")
(Error 937, Line 11, Col 6, Line 11, Col 8, "Only structs and classes without primary constructors may be given the 'StructLayout' attribute")
(Error 937, Line 14, Col 6, Line 14, Col 8, "Only structs and classes without primary constructors may be given the 'StructLayout' attribute")
(Error 937, Line 17, Col 6, Line 17, Col 8, "Only structs and classes without primary constructors may be given the 'StructLayout' attribute")
]

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

@ -0,0 +1,14 @@
[<Sealed>]
type UnnecessarilySealedStruct =
struct
member x.P = 1
end
[<Sealed>]
type BadSealedInterface =
interface
abstract P : int
end
[<Sealed>]
type UnnecessarilySealedDelegate = delegate of int -> int

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

@ -0,0 +1,17 @@
[<System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)>]
type X1 =
abstract M : unit -> 'a
[<System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)>]
[<AbstractClass>]
type X2() =
abstract M : unit -> 'a
[<System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)>]
type X4 = R1 | R2
[<System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)>]
type X5 = R1 = 1 | R2 = 2
[<System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)>]
type X6 = delegate of int -> int

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

@ -0,0 +1,31 @@
module VolatileFieldSanityChecks = begin
[<VolatileField>]
let mutable x = 1
[<VolatileField>]
let rec f x = 1
[<VolatileField>]
let x2 = 1
type C() =
[<VolatileField>]
static let sx2 = 1 // expect an error - not mutable
[<VolatileField>]
static let f x2 = 1 // expect an error - not mutable
[<VolatileField>]
let x2 = 1 // expect an error - not mutable
[<VolatileField>]
let f x2 = 1 // expect an error - not mutable
[<VolatileField>]
val mutable x : int // expect an error - not supported
member x.P = 1
end

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

@ -0,0 +1,12 @@
type InterruptibleLazy (value) =
[<VolatileField>]
let mutable valueFactory = value
[<VolatileField>]
static let mutable valueFactory2 = Unchecked.defaultof<_>
[<VolatileField>]
let mutable add1 = fun x -> x + 1
[<VolatileField>]
static let mutable add2 = fun x -> x + 1

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

@ -159,8 +159,7 @@ module CustomAttributes_Basic =
|> withLangVersionPreview
|> verifyCompile
|> shouldFail
|> withDiagnostics[
(Error 842, Line 8, Col 7, Line 8, Col 104, "This attribute is not valid for use on this language element")
|> withDiagnostics [
(Error 937, Line 9, Col 10, Line 9, Col 12, "Only structs and classes without primary constructors may be given the 'StructLayout' attribute")
]
@ -172,7 +171,6 @@ module CustomAttributes_Basic =
|> verifyCompile
|> shouldFail
|> withDiagnostics [
(Error 842, Line 8, Col 7, Line 8, Col 104, "This attribute is not valid for use on this language element")
(Error 937, Line 9, Col 10, Line 9, Col 12, "Only structs and classes without primary constructors may be given the 'StructLayout' attribute")
]
@ -184,7 +182,6 @@ module CustomAttributes_Basic =
|> verifyCompile
|> shouldFail
|> withDiagnostics [
(Error 842, Line 7, Col 7, Line 7, Col 104, "This attribute is not valid for use on this language element")
(Error 937, Line 8, Col 10, Line 8, Col 12, "Only structs and classes without primary constructors may be given the 'StructLayout' attribute")
]

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

@ -154,6 +154,7 @@ let generateProjectArtifacts (pc:ProjectConfiguration) outputType (targetFramewo
<RestoreAdditionalProjectSources Condition = "" '$(RestoreAdditionalProjectSources)' == ''"">$(RestoreFromArtifactsPath)</RestoreAdditionalProjectSources>
<RestoreAdditionalProjectSources Condition = "" '$(RestoreAdditionalProjectSources)' != ''"">$(RestoreAdditionalProjectSources);$(RestoreFromArtifactsPath)</RestoreAdditionalProjectSources>
<RollForward>LatestMajor</RollForward>
<IgnoreMIBC>true</IgnoreMIBC>
</PropertyGroup>
<!-- FSharp.Core reference -->

12
tests/fsharp/typecheck/sigs/neg06.bsl поставляемый
Просмотреть файл

@ -2,18 +2,12 @@
neg06.fs(3,40,3,45): typecheck error FS0039: The type 'Encoding' does not define the field, constructor or member 'Ascii'. Maybe you want one of the following:
ASCII
neg06.fs(11,3,11,9): typecheck error FS0842: This attribute is not valid for use on this language element
neg06.fs(12,6,12,31): typecheck error FS0942: Struct types are always sealed
neg06.fs(17,3,17,9): typecheck error FS0842: This attribute is not valid for use on this language element
neg06.fs(18,6,18,24): typecheck error FS0948: Interface types cannot be sealed
neg06.fs(24,6,24,30): typecheck error FS0944: Abbreviated types cannot be given the 'Sealed' attribute
neg06.fs(26,3,26,9): typecheck error FS0842: This attribute is not valid for use on this language element
neg06.fs(27,6,27,33): typecheck error FS0942: Delegate types are always sealed
neg06.fs(31,9,31,29): typecheck error FS0945: Cannot inherit a sealed type
@ -94,20 +88,14 @@ neg06.fs(223,13,223,21): typecheck error FS0800: Invalid use of a type name
neg06.fs(300,10,300,12): typecheck error FS0009: Uses of this construct may result in the generation of unverifiable .NET IL code. This warning can be disabled using '--nowarn:9' or '#nowarn "9"'.
neg06.fs(303,7,303,104): typecheck error FS0842: This attribute is not valid for use on this language element
neg06.fs(304,10,304,12): typecheck error FS0937: Only structs and classes without primary constructors may be given the 'StructLayout' attribute
neg06.fs(310,10,310,12): typecheck error FS0937: Only structs and classes without primary constructors may be given the 'StructLayout' attribute
neg06.fs(314,10,314,12): typecheck error FS0937: Only structs and classes without primary constructors may be given the 'StructLayout' attribute
neg06.fs(316,7,316,104): typecheck error FS0842: This attribute is not valid for use on this language element
neg06.fs(317,10,317,12): typecheck error FS0937: Only structs and classes without primary constructors may be given the 'StructLayout' attribute
neg06.fs(319,7,319,104): typecheck error FS0842: This attribute is not valid for use on this language element
neg06.fs(320,10,320,12): typecheck error FS0937: Only structs and classes without primary constructors may be given the 'StructLayout' attribute
neg06.fs(326,10,326,18): typecheck error FS0954: This type definition involves an immediate cyclic reference through a struct field or inheritance relation

2
tests/fsharp/typecheck/sigs/neg16.bsl поставляемый
Просмотреть файл

@ -73,8 +73,6 @@ neg16.fs(90,7,90,22): typecheck error FS0025: Incomplete pattern matches on this
neg16.fs(96,3,97,16): typecheck error FS0823: The 'VolatileField' attribute may only be used on 'let' bindings in classes
neg16.fs(99,5,99,18): typecheck error FS0842: This attribute is not valid for use on this language element
neg16.fs(99,3,100,14): typecheck error FS0823: The 'VolatileField' attribute may only be used on 'let' bindings in classes
neg16.fs(99,3,100,14): typecheck error FS0879: Volatile fields must be marked 'mutable' and cannot be thread-static