Skip to content

[automated] Merge branch 'main' => 'release/dev18.0' #18464

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

Merged
merged 5 commits into from
Apr 10, 2025
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
2 changes: 1 addition & 1 deletion NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<clear />
<!--Begin: Package sources managed by Dependency Flow automation. Do not edit the sources below.-->
<!-- Begin: Package sources from DotNet-msbuild-Trusted -->
<add key="darc-pub-DotNet-msbuild-Trusted-0ca03f8" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-DotNet-msbuild-Trusted-0ca03f84/nuget/v3/index.json" />
<add key="darc-pub-DotNet-msbuild-Trusted-8e42d4a" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-DotNet-msbuild-Trusted-8e42d4a4/nuget/v3/index.json" />
<!-- End: Package sources from DotNet-msbuild-Trusted -->
<!--End: Package sources managed by Dependency Flow automation. Do not edit the sources above.-->
<add key="dotnet-eng" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json" />
Expand Down
2 changes: 2 additions & 0 deletions docs/release-notes/.FSharp.Compiler.Service/9.0.300.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@
* Reenable β-reduction and subsequent reoptimization of immediately-invoked F#-defined generic delegates. ([PR #18401](https://github.com/dotnet/fsharp/pull/18401))
* Fixed [#18433](https://github.com/dotnet/fsharp/issues/18433), a rare case of an internal error in xml comment processing. ([PR #18436](https://github.com/dotnet/fsharp/pull/18436))
* Fix missing `null` highlighting in tooltips ([PR #18457](https://github.com/dotnet/fsharp/pull/18457))
* Make `[<CallerMemberName; Struct>]` combination work([PR #18444](https://github.com/dotnet/fsharp/pull/18444/))

### Added
* Added missing type constraints in FCS. ([PR #18241](https://github.com/dotnet/fsharp/pull/18241))
* The 'use' keyword can be used on IDisposable|null without nullness warnings ([PR #18262](https://github.com/dotnet/fsharp/pull/18262))
* Add support for C# `Experimental` attribute. ([PR #18253](https://github.com/dotnet/fsharp/pull/18253))
* Nullness warnings are issued for signature<>implementation conformance ([PR #18186](https://github.com/dotnet/fsharp/pull/18186))
* Symbols: Add FSharpAssembly.IsFSharp ([PR #18290](https://github.com/dotnet/fsharp/pull/18290))
* Type checker: don't suppress errors while checking expressions ([PR #18311](https://github.com/dotnet/fsharp/pull/18311))
* Type parameter constraint `null` in generic code will now automatically imply `not struct` ([Issue #18320](https://github.com/dotnet/fsharp/issues/18320), [PR #18323](https://github.com/dotnet/fsharp/pull/18323))
* Add a switch to determine whether to generate a default implementation body for overridden method when completing. [PR #18341](https://github.com/dotnet/fsharp/pull/18341)
* Use a more accurate range for CE Combine methods. [PR #18394](https://github.com/dotnet/fsharp/pull/18394)
Expand Down
28 changes: 14 additions & 14 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@
<SourceBuild RepoName="source-build-reference-packages" ManagedOnly="true" />
</Dependency>
<!-- Intermediate is necessary for source build. -->
<Dependency Name="Microsoft.SourceBuild.Intermediate.msbuild" Version="17.13.22-preview-25174-08">
<Dependency Name="Microsoft.SourceBuild.Intermediate.msbuild" Version="17.13.23-preview-25208-06">
<Uri>https://github.com/dotnet/msbuild</Uri>
<Sha>0ca03f84b7848ce9d7d3e5d1f68c5e090efa4f30</Sha>
<Sha>8e42d4a440e0f85c1e8dce43767e7a50d86aa8ff</Sha>
<SourceBuild RepoName="msbuild" ManagedOnly="true" />
</Dependency>
<Dependency Name="Microsoft.Build" Version="17.13.22">
<Dependency Name="Microsoft.Build" Version="17.13.23">
<Uri>https://github.com/dotnet/msbuild</Uri>
<Sha>0ca03f84b7848ce9d7d3e5d1f68c5e090efa4f30</Sha>
<Sha>8e42d4a440e0f85c1e8dce43767e7a50d86aa8ff</Sha>
</Dependency>
<Dependency Name="Microsoft.Build.Framework" Version="17.13.22">
<Dependency Name="Microsoft.Build.Framework" Version="17.13.23">
<Uri>https://github.com/dotnet/msbuild</Uri>
<Sha>0ca03f84b7848ce9d7d3e5d1f68c5e090efa4f30</Sha>
<Sha>8e42d4a440e0f85c1e8dce43767e7a50d86aa8ff</Sha>
</Dependency>
<Dependency Name="Microsoft.Build.Tasks.Core" Version="17.13.22">
<Dependency Name="Microsoft.Build.Tasks.Core" Version="17.13.23">
<Uri>https://github.com/dotnet/msbuild</Uri>
<Sha>0ca03f84b7848ce9d7d3e5d1f68c5e090efa4f30</Sha>
<Sha>8e42d4a440e0f85c1e8dce43767e7a50d86aa8ff</Sha>
</Dependency>
<Dependency Name="Microsoft.Build.Utilities.Core" Version="17.13.22">
<Dependency Name="Microsoft.Build.Utilities.Core" Version="17.13.23">
<Uri>https://github.com/dotnet/msbuild</Uri>
<Sha>0ca03f84b7848ce9d7d3e5d1f68c5e090efa4f30</Sha>
<Sha>8e42d4a440e0f85c1e8dce43767e7a50d86aa8ff</Sha>
</Dependency>
<Dependency Name="System.Reflection.Metadata" Version="8.0.0">
<Uri>https://github.com/dotnet/runtime</Uri>
Expand All @@ -42,14 +42,14 @@
</Dependency>
</ProductDependencies>
<ToolsetDependencies>
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="9.0.0-beta.25204.5">
<Dependency Name="Microsoft.DotNet.Arcade.Sdk" Version="9.0.0-beta.25208.6">
<Uri>https://github.com/dotnet/arcade</Uri>
<Sha>97cbc7361ff28b2948c8182720c166a744049f55</Sha>
<Sha>aa61e8c20a869bcc994f8b29eb07d927d2bec6f4</Sha>
</Dependency>
<!-- Intermediate is necessary for source build. -->
<Dependency Name="Microsoft.SourceBuild.Intermediate.arcade" Version="9.0.0-beta.25204.5">
<Dependency Name="Microsoft.SourceBuild.Intermediate.arcade" Version="9.0.0-beta.25208.6">
<Uri>https://github.com/dotnet/arcade</Uri>
<Sha>97cbc7361ff28b2948c8182720c166a744049f55</Sha>
<Sha>aa61e8c20a869bcc994f8b29eb07d927d2bec6f4</Sha>
<SourceBuild RepoName="arcade" ManagedOnly="true" />
</Dependency>
<Dependency Name="optimization.windows_nt-x64.MIBC.Runtime" Version="1.0.0-prerelease.24462.2">
Expand Down
8 changes: 4 additions & 4 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
<MicrosoftVisualStudioShellPackagesVersion>17.10.40152</MicrosoftVisualStudioShellPackagesVersion>
<VisualStudioProjectSystemPackagesVersion>17.10.526-pre-g1b474069f5</VisualStudioProjectSystemPackagesVersion>
<MicrosoftVisualStudioThreadingPackagesVersion>17.10.41</MicrosoftVisualStudioThreadingPackagesVersion>
<MicrosoftBuildVersion>17.13.22</MicrosoftBuildVersion>
<MicrosoftBuildVersion>17.13.23</MicrosoftBuildVersion>
<!-- Roslyn packages -->
<MicrosoftCodeAnalysisEditorFeaturesVersion>$(RoslynVersion)</MicrosoftCodeAnalysisEditorFeaturesVersion>
<MicrosoftCodeAnalysisEditorFeaturesTextVersion>$(RoslynVersion)</MicrosoftCodeAnalysisEditorFeaturesTextVersion>
Expand Down Expand Up @@ -138,9 +138,9 @@
<MicrosoftVisualStudioShellImmutable150Version>15.0.25123-Dev15Preview</MicrosoftVisualStudioShellImmutable150Version>
<!-- -->
<!-- Microsoft Build packages -->
<MicrosoftBuildFrameworkVersion>17.13.22</MicrosoftBuildFrameworkVersion>
<MicrosoftBuildTasksCoreVersion>17.13.22</MicrosoftBuildTasksCoreVersion>
<MicrosoftBuildUtilitiesCoreVersion>17.13.22</MicrosoftBuildUtilitiesCoreVersion>
<MicrosoftBuildFrameworkVersion>17.13.23</MicrosoftBuildFrameworkVersion>
<MicrosoftBuildTasksCoreVersion>17.13.23</MicrosoftBuildTasksCoreVersion>
<MicrosoftBuildUtilitiesCoreVersion>17.13.23</MicrosoftBuildUtilitiesCoreVersion>
<!-- -->
<!-- Visual Studio Editor packages -->
<MicrosoftVisualStudioCoreUtilityVersion>$(VisualStudioEditorPackagesVersion)</MicrosoftVisualStudioCoreUtilityVersion>
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"perl": "5.38.2.2"
},
"msbuild-sdks": {
"Microsoft.DotNet.Arcade.Sdk": "9.0.0-beta.25204.5",
"Microsoft.DotNet.Arcade.Sdk": "9.0.0-beta.25208.6",
"Microsoft.DotNet.Helix.Sdk": "8.0.0-beta.23255.2"
}
}
62 changes: 27 additions & 35 deletions src/Compiler/Checking/Expressions/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5960,7 +5960,7 @@ and TcExprUndelayed (cenv: cenv) (overallTy: OverallTy) env tpenv (synExpr: SynE

| SynExpr.FromParseError (expr1, m) ->
//SolveTypeAsError cenv env.DisplayEnv m overallTy
let _, tpenv = suppressErrorReporting (fun () -> TcExpr cenv overallTy env tpenv expr1)
let _, tpenv = TcExpr cenv overallTy env tpenv expr1
mkDefault(m, overallTy.Commit), tpenv

| SynExpr.Sequential (sp, dir, synExpr1, synExpr2, m, _) ->
Expand Down Expand Up @@ -6489,9 +6489,7 @@ and TcIteratedLambdas (cenv: cenv) isFirst (env: TcEnv) overallTy takenNames tpe

| e ->
let env = { env with eIsControlFlow = true }
// Dive into the expression to check for syntax errors and suppress them if they show.
conditionallySuppressErrorReporting (not isFirst && synExprContainsError e) (fun () ->
TcExpr cenv overallTy env tpenv e)
TcExpr cenv overallTy env tpenv e

and TcTyparExprThen (cenv: cenv) overallTy env tpenv synTypar m delayed =
match delayed with
Expand Down Expand Up @@ -11103,39 +11101,33 @@ and TcNormalizedBinding declKind (cenv: cenv) env tpenv overallTy safeThisValOpt
// At each module binding, dive into the expression to check for syntax errors and suppress them if they show.
// Don't do this for lambdas, because we always check for suppression for all lambda bodies in TcIteratedLambdas
let rhsExprChecked, tpenv =
let atTopNonLambdaDefn =
declKind.IsModuleOrMemberOrExtensionBinding &&
(match rhsExpr with SynExpr.Lambda _ -> false | _ -> true) &&
synExprContainsError rhsExpr

conditionallySuppressErrorReporting atTopNonLambdaDefn (fun () ->

// Save the arginfos away to match them up in the lambda
let (PrelimValReprInfo(argInfos, _)) = prelimValReprInfo

// The right-hand-side is control flow (has an implicit debug point) in any situation where we
// haven't extended the debug point to include the 'let', that is, there is a debug point noted
// at the binding.
//
// This includes
// let _ = expr
// let () = expr
// which are transformed to sequential expressions in TcLetBinding
//
let rhsIsControlFlow =
match pat with
| SynPat.Wild _
| SynPat.Const (SynConst.Unit, _)
| SynPat.Paren (SynPat.Const (SynConst.Unit, _), _) -> true
| _ ->
match debugPoint with
| DebugPointAtBinding.Yes _ -> false
| _ -> true
// Save the arginfos away to match them up in the lambda
let (PrelimValReprInfo(argInfos, _)) = prelimValReprInfo

// The right-hand-side is control flow (has an implicit debug point) in any situation where we
// haven't extended the debug point to include the 'let', that is, there is a debug point noted
// at the binding.
//
// This includes
// let _ = expr
// let () = expr
// which are transformed to sequential expressions in TcLetBinding
//
let rhsIsControlFlow =
match pat with
| SynPat.Wild _
| SynPat.Const (SynConst.Unit, _)
| SynPat.Paren (SynPat.Const (SynConst.Unit, _), _) -> true
| _ ->

match debugPoint with
| DebugPointAtBinding.Yes _ -> false
| _ -> true

let envinner = { envinner with eLambdaArgInfos = argInfos; eIsControlFlow = rhsIsControlFlow }
let envinner = { envinner with eLambdaArgInfos = argInfos; eIsControlFlow = rhsIsControlFlow }

if isCtor then TcExprThatIsCtorBody (safeThisValOpt, safeInitInfo) cenv (MustEqual overallExprTy) envinner tpenv rhsExpr
else TcExprThatCantBeCtorBody cenv (MustConvertTo (false, overallExprTy)) envinner tpenv rhsExpr)
if isCtor then TcExprThatIsCtorBody (safeThisValOpt, safeInitInfo) cenv (MustEqual overallExprTy) envinner tpenv rhsExpr
else TcExprThatCantBeCtorBody cenv (MustConvertTo (false, overallExprTy)) envinner tpenv rhsExpr

if kind = SynBindingKind.StandaloneExpression && not cenv.isScript then
UnifyUnitType cenv env mBinding overallPatTy rhsExprChecked |> ignore<bool>
Expand Down
12 changes: 9 additions & 3 deletions src/Compiler/Checking/MethodCalls.fs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,12 @@ let inline mkOptionalNone (g: TcGlobals) ty calledArgTy mMethExpr =
else
mkNone g calledArgTy mMethExpr

let inline mkOptionalSome (g: TcGlobals) outerOptTy innerNonOptionalType expr mMethExpr =
if g.langVersion.SupportsFeature LanguageFeature.SupportValueOptionsAsOptionalParameters && isValueOptionTy g outerOptTy then
mkValueSome g innerNonOptionalType expr mMethExpr
else
mkSome g innerNonOptionalType expr mMethExpr


/// Adjust the called argument type to take into account whether the caller's argument is CSharpMethod(?arg=Some(3)) or CSharpMethod(arg=1)
let AdjustCalledArgTypeForOptionals (infoReader: InfoReader) ad enforceNullableOptionalsKnownTypes (calledArg: CalledArg) calledArgTy (callerArg: CallerArg<_>) =
Expand Down Expand Up @@ -1502,14 +1508,14 @@ let GetDefaultExpressionForCalleeSideOptionalArg g (calledArg: CalledArg) eCalle
match calledArg.CallerInfo, eCallerMemberName with
| CallerLineNumber, _ when typeEquiv g calledNonOptTy g.int_ty ->
let lineExpr = Expr.Const(Const.Int32 mMethExpr.StartLine, mMethExpr, calledNonOptTy)
mkSome g calledNonOptTy lineExpr mMethExpr
mkOptionalSome g calledArgTy calledNonOptTy lineExpr mMethExpr
| CallerFilePath, _ when typeEquiv g calledNonOptTy g.string_ty ->
let fileName = mMethExpr.FileName |> FileSystem.GetFullPathShim |> PathMap.apply g.pathMap
let filePathExpr = Expr.Const (Const.String(fileName), mMethExpr, calledNonOptTy)
mkSome g calledNonOptTy filePathExpr mMethExpr
mkOptionalSome g calledArgTy calledNonOptTy filePathExpr mMethExpr
| CallerMemberName, Some(callerName) when typeEquiv g calledNonOptTy g.string_ty ->
let memberNameExpr = Expr.Const (Const.String callerName, mMethExpr, calledNonOptTy)
mkSome g calledNonOptTy memberNameExpr mMethExpr
mkOptionalSome g calledArgTy calledNonOptTy memberNameExpr mMethExpr
| _ ->
mkOptionalNone g calledArgTy calledNonOptTy mMethExpr

Expand Down
26 changes: 18 additions & 8 deletions src/Compiler/Checking/PostInferenceChecks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2398,13 +2398,25 @@ let CheckEntityDefn cenv env (tycon: Entity) =
errorR(Error(FSComp.SR.chkCurriedMethodsCantHaveOutParams(), m))

if numCurriedArgSets = 1 then
let errorIfNotStringTy m ty callerInfo =

let inline tryDestOptionalTy g ty =
if isOptionTy g ty then
destOptionTy g ty |> ValueSome
elif g.langVersion.SupportsFeature LanguageFeature.SupportValueOptionsAsOptionalParameters && isValueOptionTy g ty then
destValueOptionTy g ty |> ValueSome
else
ValueNone

let errorIfNotStringTy m ty callerInfo =
if not (typeEquiv g g.string_ty ty) then
errorR(Error(FSComp.SR.tcCallerInfoWrongType(callerInfo |> string, "string", NicePrint.minimalStringOfType cenv.denv ty), m))

let errorIfNotOptional tyToCompare desiredTyName m ty callerInfo =

let errorIfNotStringOptionTy m ty callerInfo =
if not ((isOptionTy g ty) && (typeEquiv g g.string_ty (destOptionTy g ty))) then
errorR(Error(FSComp.SR.tcCallerInfoWrongType(callerInfo |> string, "string", NicePrint.minimalStringOfType cenv.denv (destOptionTy g ty)), m))
match tryDestOptionalTy g ty with
| ValueSome t when typeEquiv g tyToCompare t -> ()
| ValueSome innerTy -> errorR(Error(FSComp.SR.tcCallerInfoWrongType(callerInfo |> string, desiredTyName, NicePrint.minimalStringOfType cenv.denv innerTy), m))
| ValueNone -> errorR(Error(FSComp.SR.tcCallerInfoWrongType(callerInfo |> string, desiredTyName, NicePrint.minimalStringOfType cenv.denv ty), m))

minfo.GetParamDatas(cenv.amap, m, minfo.FormalMethodInst)
|> List.iterSquared (fun (ParamData(_, isInArg, _, optArgInfo, callerInfo, nameOpt, _, ty)) ->
Expand All @@ -2421,11 +2433,9 @@ let CheckEntityDefn cenv env (tycon: Entity) =
| CallerSide _, CallerLineNumber ->
if not (typeEquiv g g.int32_ty ty) then
errorR(Error(FSComp.SR.tcCallerInfoWrongType(callerInfo |> string, "int", NicePrint.minimalStringOfType cenv.denv ty), m))
| CalleeSide, CallerLineNumber ->
if not ((isOptionTy g ty) && (typeEquiv g g.int32_ty (destOptionTy g ty))) then
errorR(Error(FSComp.SR.tcCallerInfoWrongType(callerInfo |> string, "int", NicePrint.minimalStringOfType cenv.denv (destOptionTy g ty)), m))
| CalleeSide, CallerLineNumber -> errorIfNotOptional g.int32_ty "int" m ty callerInfo
| CallerSide _, (CallerFilePath | CallerMemberName) -> errorIfNotStringTy m ty callerInfo
| CalleeSide, (CallerFilePath | CallerMemberName) -> errorIfNotStringOptionTy m ty callerInfo
| CalleeSide, (CallerFilePath | CallerMemberName) -> errorIfNotOptional g.string_ty "string" m ty callerInfo
)

for pinfo in immediateProps do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,4 +609,41 @@ but here has type
''T option'
but here has type
''a voption' "
]
]

[<Fact>]
let ``Struct optional args can have caller member name`` () =

let source = """module TestLib
open System.Runtime.CompilerServices

let printItOut x =
printf "%s" $"{x};"

type Ab() =

static member aa ([<CallerMemberName; Struct>]?b: string) =
printItOut b

static member bb ([<CallerLineNumber; Struct>]?i: int) =
printItOut i

[<EntryPoint>]
let main _args =
Ab.aa()
Ab.bb()
Ab.aa("hello")
Ab.bb(42)
0
"""

source
|> FSharp
|> withLangVersionPreview
|> withNoWarn 25
|> asExe
|> compile
|> ILVerifierModule.verifyPEFileWithSystemDlls
|> run
|> verifyOutputContains [|"main;18;hello;42;"|]

9 changes: 7 additions & 2 deletions tests/FSharp.Compiler.Service.Tests/Common.fs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ let mkProjectCommandLineArgsForScript (dllName, fileNames) =
yield "--doc:test.xml"
yield "--warn:3"
yield "--fullpaths"
yield "--flaterrors"
yield "--target:library"
for x in fileNames do
yield x
Expand Down Expand Up @@ -370,11 +369,17 @@ let inline dumpDiagnostics (results: FSharpCheckFileResults) =
|> Array.map (fun e ->
let message =
e.Message.Split('\n')
|> Array.map (fun s -> s.Trim())
|> Array.map _.Trim()
|> Array.filter (fun s -> s.Length > 0)
|> String.concat " "
sprintf "%s: %s" (e.Range.ToString()) message)
|> List.ofArray

let inline dumpDiagnosticNumbers (results: FSharpCheckFileResults) =
results.Diagnostics
|> Array.map (fun e -> e.Range.ToString(), e.ErrorNumber)
|> List.ofArray

let getSymbolUses (results: FSharpCheckFileResults) =
results.GetAllUsesOfAllSymbolsInFile()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<Link>XunitSetup.fs</Link>
</Compile>
<Compile Include="Common.fs" />
<Compile Include="TypeChecker\TypeCheckerRecoveryTests.fs" />
<Compile Include="GeneratedCodeSymbolsTests.fs" />
<Compile Include="AssemblyReaderShim.fs" />
<Compile Include="ModuleReaderCancellationTests.fs" />
Expand Down
Loading
Loading