Skip to content

[RFC FS-1075] Improve interop to C# nullable-typed optionals #7989

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 30 commits into from
Feb 5, 2020
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
37aba11
add test cases we need to make work
dsyme Jul 25, 2019
a497ef9
cleanup method call argument processing
dsyme Jul 26, 2019
59ff269
Merge branch 'master' of http://github.com/Microsoft/visualfsharp int…
dsyme Jul 26, 2019
43489f3
Merge branch 'master' of http://github.com/Microsoft/visualfsharp int…
dsyme Jul 29, 2019
1952635
update for new cases
dsyme Jul 29, 2019
072e129
update tests
dsyme Jul 30, 2019
9cff571
compat Nullable allowed
dsyme Jul 30, 2019
ef0d87b
Merge branch 'master' of http://github.com/Microsoft/visualfsharp int…
dsyme Jul 31, 2019
4c065c5
reduce diff
dsyme Jul 31, 2019
d5ccece
fix mistake with byrefs
dsyme Jul 31, 2019
9864bd0
update error message
dsyme Jul 31, 2019
cdc2064
Merge branch 'master' of https://github.com/dotnet/fsharp into option…
dsyme Sep 3, 2019
75e06a2
integrate master
dsyme Oct 15, 2019
41a062e
Merge branch 'optionals2' of https://github.com/dsyme/visualfsharp in…
dsyme Oct 15, 2019
695604f
Merge branch 'master' of https://github.com/dotnet/fsharp into option…
dsyme Dec 16, 2019
e692e46
trigger CI
dsyme Dec 16, 2019
05bb54f
add version tests
dsyme Dec 16, 2019
bc48617
Merge branch 'master' of https://github.com/dotnet/fsharp into option…
dsyme Dec 16, 2019
66a7886
Merge branch 'master' into feature/nullable-optionals
cartermp Dec 24, 2019
27b19e7
Merge branch 'master' of https://github.com/dotnet/fsharp into featur…
dsyme Jan 8, 2020
15141c2
mnimize diff
dsyme Jan 9, 2020
bd742c3
mnimize diff
dsyme Jan 9, 2020
18a2d37
remove assert
dsyme Jan 9, 2020
be2c8fb
integrate master
dsyme Jan 10, 2020
84be801
Merge branch 'master' of https://github.com/dotnet/fsharp into featur…
dsyme Jan 14, 2020
ff78936
merge master
dsyme Jan 28, 2020
6f5b88f
Merge branch 'master' of https://github.com/dotnet/fsharp into featur…
dsyme Jan 29, 2020
78f1db8
minor updates for code review
dsyme Jan 29, 2020
13b26a7
fix overloading change of behaviour
dsyme Jan 29, 2020
e69ddce
Merge branch 'master' of https://github.com/dotnet/fsharp into featur…
dsyme Jan 31, 2020
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,4 @@ If you're curious about F# itself, check out these links:
* [Get started with F#](https://docs.microsoft.com/dotnet/fsharp/get-started/)
* [F# Software Foundation](https://fsharp.org)
* [F# Testimonials](https://fsharp.org/testimonials)

17 changes: 9 additions & 8 deletions src/fsharp/ConstraintSolver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2209,14 +2209,15 @@ and ArgsMustSubsumeOrConvert
trace
cxsln
isConstraint
enforceNullableOptionalsKnownTypes // use known types from nullable optional args?
(calledArg: CalledArg)
(callerArg: CallerArg<'T>) = trackErrors {

let g = csenv.g
let m = callerArg.Range
let calledArgTy = AdjustCalledArgType csenv.InfoReader isConstraint calledArg callerArg
do! SolveTypeSubsumesTypeWithReport csenv ndeep m trace cxsln calledArgTy callerArg.Type
if calledArg.IsParamArray && isArray1DTy g calledArgTy && not (isArray1DTy g callerArg.Type) then
let calledArgTy = AdjustCalledArgType csenv.InfoReader isConstraint enforceNullableOptionalsKnownTypes calledArg callerArg
do! SolveTypeSubsumesTypeWithReport csenv ndeep m trace cxsln calledArgTy callerArg.CallerArgumentType
if calledArg.IsParamArray && isArray1DTy g calledArgTy && not (isArray1DTy g callerArg.CallerArgumentType) then
return! ErrorD(Error(FSComp.SR.csMethodExpectsParams(), m))
else ()
}
Expand All @@ -2228,14 +2229,14 @@ and MustUnifyInsideUndo csenv ndeep trace cxsln ty1 ty2 =
SolveTypeEqualsTypeWithReport csenv ndeep csenv.m (WithTrace trace) cxsln ty1 ty2

and ArgsMustSubsumeOrConvertInsideUndo (csenv: ConstraintSolverEnv) ndeep trace cxsln isConstraint calledArg (CallerArg(callerArgTy, m, _, _) as callerArg) =
let calledArgTy = AdjustCalledArgType csenv.InfoReader isConstraint calledArg callerArg
let calledArgTy = AdjustCalledArgType csenv.InfoReader isConstraint true calledArg callerArg
SolveTypeSubsumesTypeWithReport csenv ndeep m (WithTrace trace) cxsln calledArgTy callerArgTy

and TypesMustSubsumeOrConvertInsideUndo (csenv: ConstraintSolverEnv) ndeep trace cxsln m calledArgTy callerArgTy =
SolveTypeSubsumesTypeWithReport csenv ndeep m trace cxsln calledArgTy callerArgTy

and ArgsEquivInsideUndo (csenv: ConstraintSolverEnv) isConstraint calledArg (CallerArg(callerArgTy, m, _, _) as callerArg) =
let calledArgTy = AdjustCalledArgType csenv.InfoReader isConstraint calledArg callerArg
let calledArgTy = AdjustCalledArgType csenv.InfoReader isConstraint true calledArg callerArg
if typeEquiv csenv.g calledArgTy callerArgTy then CompleteD else ErrorD(Error(FSComp.SR.csArgumentTypesDoNotMatch(), m))

and ReportNoCandidatesError (csenv: ConstraintSolverEnv) (nUnnamedCallerArgs, nNamedCallerArgs) methodName ad (calledMethGroup: CalledMeth<_> list) isSequential =
Expand Down Expand Up @@ -2534,7 +2535,7 @@ and ResolveOverloading
// Prefer methods with more precise param array arg type
let c =
if candidate.UsesParamArrayConversion && other.UsesParamArrayConversion then
compareTypes candidate.ParamArrayElementType other.ParamArrayElementType
compareTypes (candidate.GetParamArrayElementType()) (other.GetParamArrayElementType())
else
0
if c <> 0 then c else
Expand Down Expand Up @@ -2654,7 +2655,7 @@ and ResolveOverloading
true
(MustUnify csenv ndeep trace cxsln)
(TypesMustSubsumeOrConvertInsideUndo csenv ndeep trace cxsln m)// REVIEW: this should not be an "InsideUndo" operation
(ArgsMustSubsumeOrConvert csenv ndeep trace cxsln cx.IsSome)
(ArgsMustSubsumeOrConvert csenv ndeep trace cxsln cx.IsSome true)
reqdRetTyOpt
calledMeth
| WithTrace calledMethTrc ->
Expand Down Expand Up @@ -2701,7 +2702,7 @@ let UnifyUniqueOverloading
true // always check return type
(MustUnify csenv ndeep NoTrace None)
(TypesMustSubsumeOrConvertInsideUndo csenv ndeep NoTrace None m)
(ArgsMustSubsumeOrConvert csenv ndeep NoTrace None false) // UnifyUniqueOverloading is not called in case of trait call - pass isConstraint=false
(ArgsMustSubsumeOrConvert csenv ndeep NoTrace None false false) // UnifyUniqueOverloading is not called in case of trait call - pass isConstraint=false
(Some reqdRetTy)
calledMeth
return true
Expand Down
1 change: 0 additions & 1 deletion src/fsharp/FSharp.Core/option.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ module Option =
[<CompiledName("ToList")>]
val toList: option:'T option -> 'T list


/// <summary>Convert the option to a Nullable value.</summary>
/// <param name="option">The input option.</param>
/// <returns>The result value.</returns>
Expand Down
1 change: 0 additions & 1 deletion src/fsharp/IlxGen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5089,7 +5089,6 @@ and GenDecisionTreeSwitch cenv cgbuf inplabOpt stackAtTargets eenv e cases defau
| _ -> error(InternalError("these matches should never be needed", switchm))

and GenDecisionTreeCases cenv cgbuf stackAtTargets eenv defaultTargetOpt targets repeatSP targetInfos sequel caseLabels cases (contf: Zmap<_,_> -> FakeUnit) =
assert(cgbuf.GetCurrentStack() = stackAtTargets) // cgbuf stack should be unchanged over tests. [bug://1750].

match defaultTargetOpt with
| Some defaultTarget ->
Expand Down
2 changes: 2 additions & 0 deletions src/fsharp/LanguageFeatures.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type LanguageFeature =
| PackageManagement
| FromEndSlicing
| FixedIndexSlice3d4d
| NullableOptionalInterop

/// LanguageVersion management
type LanguageVersion (specifiedVersionAsString) =
Expand Down Expand Up @@ -61,6 +62,7 @@ type LanguageVersion (specifiedVersionAsString) =
LanguageFeature.OpenStaticClasses, previewVersion
LanguageFeature.DotlessFloat32Literal, languageVersion50
LanguageFeature.PackageManagement, previewVersion
LanguageFeature.NullableOptionalInterop, previewVersion
]

let specified =
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/LanguageFeatures.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type LanguageFeature =
| PackageManagement
| FromEndSlicing
| FixedIndexSlice3d4d

| NullableOptionalInterop

/// LanguageVersion management
type LanguageVersion =
Expand Down
Loading