Skip to content

Commit 0fdbf2d

Browse files
authored
Merge pull request #428 from fsprojects/repo-assist/fix-issue-346-all-optional-static-params-d0cd3d307992ff72
[Repo Assist] Warn when all static parameters are optional (fix #346)
2 parents 90e8e35 + fed4272 commit 0fdbf2d

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/ProvidedTypes.fs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,6 +1830,12 @@ and ProvidedTypeDefinition(isTgt: bool, container:TypeContainer, className: stri
18301830
member __.DefineStaticParameters(parameters: ProvidedStaticParameter list, instantiationFunction: (string -> obj[] -> ProvidedTypeDefinition)) =
18311831
if staticParamsDefined then failwithf "Static parameters have already been defined for this type. stacktrace = %A" Environment.StackTrace
18321832
staticParamsDefined <- true
1833+
// Warn when all static parameters are optional. This can cause issues when the user provides
1834+
// values that exactly match the defaults (see https://github.com/fsprojects/FSharp.TypeProviders.SDK/issues/346).
1835+
if parameters.Length > 0 && parameters |> List.forall (fun p -> p.ParameterDefaultValue.IsSome) then
1836+
match !ProvidedTypeDefinition.Logger with
1837+
| Some logger -> logger (sprintf "WARNING: ProvidedTypeDefinition '%s' has all static parameters defined as optional. This can cause issues when all provided argument values match the defaults. Consider making at least one static parameter non-optional." className)
1838+
| None -> eprintfn "WARNING (TypeProviders SDK): ProvidedTypeDefinition '%s' has all static parameters defined as optional. This can cause issues when all provided argument values match the defaults. Consider making at least one static parameter non-optional." className
18331839
staticParams <- lazy parameters
18341840
staticParamsApply <- Some instantiationFunction
18351841

0 commit comments

Comments
 (0)