Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET Platform
fsharp
提交
539d5ab5
F
fsharp
项目概览
dotNET Platform
/
fsharp
12 个月 前同步成功
通知
0
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
fsharp
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
539d5ab5
编写于
12月 02, 2020
作者:
W
Will Smith
提交者:
GitHub
12月 02, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix generic overloads with nullable (#10582)
上级
fc9992a1
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
156 addition
and
3 deletion
+156
-3
src/fsharp/MethodCalls.fs
src/fsharp/MethodCalls.fs
+9
-3
tests/fsharp/Compiler/Language/OptionalInteropTests.fs
tests/fsharp/Compiler/Language/OptionalInteropTests.fs
+111
-0
tests/fsharp/Compiler/Regressions/NullableOptionalRegressionTests.fs
...p/Compiler/Regressions/NullableOptionalRegressionTests.fs
+35
-0
tests/fsharp/FSharpSuite.Tests.fsproj
tests/fsharp/FSharpSuite.Tests.fsproj
+1
-0
未找到文件。
src/fsharp/MethodCalls.fs
浏览文件 @
539d5ab5
...
...
@@ -209,10 +209,16 @@ let AdjustCalledArgTypeForOptionals (g: TcGlobals) enforceNullableOptionalsKnown
// If neither and we are at the end of overload resolution then use the Nullable
elif
enforceNullableOptionalsKnownTypes
then
calledArgTy
// If at the beginning of inference then use a type variable
// If at the beginning of inference then use a type variable
.
else
let
compgenId
=
mkSynId
range0
unassignedTyparName
mkTyparTy
(
Construct
.
NewTypar
(
TyparKind
.
Type
,
TyparRigidity
.
Flexible
,
Typar
(
compgenId
,
NoStaticReq
,
true
),
false
,
TyparDynamicReq
.
No
,
[]
,
false
,
false
))
let
destTy
=
destNullableTy
g
calledArgTy
match
calledArg
.
OptArgInfo
with
// Use the type variable from the Nullable if called arg is not optional.
|
NotOptional
when
isTyparTy
g
destTy
->
destTy
|
_
->
let
compgenId
=
mkSynId
range0
unassignedTyparName
mkTyparTy
(
Construct
.
NewTypar
(
TyparKind
.
Type
,
TyparRigidity
.
Flexible
,
Typar
(
compgenId
,
NoStaticReq
,
true
),
false
,
TyparDynamicReq
.
No
,
[]
,
false
,
false
))
else
calledArgTy
...
...
tests/fsharp/Compiler/Language/OptionalInteropTests.fs
浏览文件 @
539d5ab5
...
...
@@ -23,6 +23,94 @@ namespace CSharpTest
public static class Test
{
public static void M(FSharpOption<int> x = null) { }
public static int MethodTakingOptionals(int x = 3, string y = "
abc
", double d = 5.0)
{
return x + y.Length + (int) d;
}
public static int MethodTakingNullableOptionalsWithDefaults(int? x = 3, string y = "
abc
", double? d = 5.0)
{
return (x.HasValue ? x.Value : -100) + y.Length + (int) (d.HasValue ? d.Value : 0.0);
}
public static int MethodTakingNullableOptionals(int? x = null, string y = null, double? d = null)
{
int length;
if (y == null)
length = -1;
else
length = y.Length;
return (x.HasValue ? x.Value : -1) + length + (int) (d.HasValue ? d.Value : -1.0);
}
public static int OverloadedMethodTakingOptionals(int x = 3, string y = "
abc
", double d = 5.0)
{
return x + y.Length + (int) d;
}
public static int OverloadedMethodTakingOptionals(int x = 3, string y = "
abc
", System.Single d = 5.0f)
{
return x + y.Length + (int) d + 7;
}
public static int OverloadedMethodTakingNullableOptionalsWithDefaults(int? x = 3, string y = "
abc
", double? d = 5.0)
{
return (x.HasValue ? x.Value : -100) + y.Length + (int) (d.HasValue ? d.Value : 0.0);
}
public static int OverloadedMethodTakingNullableOptionalsWithDefaults(long? x = 3, string y = "
abc
", double? d = 5.0)
{
return (x.HasValue ? (int) x.Value : -100) + y.Length + (int) (d.HasValue ? d.Value : 0.0) + 7;
}
public static int OverloadedMethodTakingNullableOptionals(int? x = null, string y = null, double? d = null)
{
int length;
if (y == null)
length = -1;
else
length = y.Length;
return (x.HasValue ? x.Value : -1) + length + (int) (d.HasValue ? d.Value : -1.0);
}
public static int OverloadedMethodTakingNullableOptionals(long? x = null, string y = null, double? d = null)
{
int length;
if (y == null)
length = -1;
else
length = y.Length;
return (x.HasValue ? (int) x.Value : -1) + length + (int) (d.HasValue ? d.Value : -1.0) + 7;
}
public static int MethodTakingNullables(int? x, string y, double? d)
{
int length;
if (y == null)
length = -1;
else
length = y.Length;
return (x.HasValue ? x.Value : -1) + length + (int) (d.HasValue ? d.Value : -1.0);
}
public static int OverloadedMethodTakingNullables(int? x, string y, double? d)
{
int length;
if (y == null)
length = -1;
else
length = y.Length;
return (x.HasValue ? x.Value : -1) + length + (int) (d.HasValue ? d.Value : -1.0);
}
public static int OverloadedMethodTakingNullables(long? x, string y, double? d)
{
int length;
if (y == null)
length = -1;
else
length = y.Length;
return (x.HasValue ? (int) x.Value : -1) + length + (int) (d.HasValue ? d.Value : -1.0) + 7;
}
public static int SimpleOverload(int? x = 3)
{
return (x.HasValue ? x.Value : 100);
}
public static int SimpleOverload(int x = 3)
{
return (x + 200);
}
}
}
"""
...
...
@@ -33,6 +121,29 @@ open System
open CSharpTest
Test.M(x = Some 1)
Test.MethodTakingNullables(6, "
aaaaaa
", 8.0) |> ignore
Test.MethodTakingNullables(6, "
aaaaaa
", Nullable 8.0) |> ignore
Test.MethodTakingNullables(6, "
aaaaaa
", Nullable ()) |> ignore
Test.MethodTakingNullables(Nullable (), "
aaaaaa
", 8.0) |> ignore
Test.MethodTakingNullables(Nullable 6, "
aaaaaa
", 8.0) |> ignore
Test.MethodTakingNullables(6, "
aaaaaa
", d=8.0) |> ignore
Test.MethodTakingNullables(6, "
aaaaaa
", d=Nullable 8.0) |> ignore
Test.MethodTakingNullables(6, "
aaaaaa
", d=Nullable ()) |> ignore
Test.MethodTakingNullables(Nullable (), "
aaaaaa
", d=8.0) |> ignore
Test.MethodTakingNullables(Nullable 6, "
aaaaaa
", d=8.0) |> ignore
Test.MethodTakingNullables(6, y="
aaaaaa
", d=8.0) |> ignore
Test.MethodTakingNullables(6, y="
aaaaaa
", d=Nullable 8.0) |> ignore
Test.MethodTakingNullables(6, y="
aaaaaa
", d=Nullable ()) |> ignore
Test.MethodTakingNullables(Nullable (), y="
aaaaaa
", d=8.0) |> ignore
Test.MethodTakingNullables(Nullable 6, y="
aaaaaa
", d=8.0) |> ignore
Test.MethodTakingNullables(6, y="
aaaaaa
", d=8.0) |> ignore
Test.MethodTakingNullables(6, y="
aaaaaa
", d=Nullable 8.0) |> ignore
Test.MethodTakingNullables(6, y="
aaaaaa
", d=Nullable ()) |> ignore
Test.MethodTakingNullables(Nullable (), y="
aaaaaa
", d=8.0) |> ignore
Test.MethodTakingNullables(Nullable 6, y="
aaaaaa
", d=8.0) |> ignore
"""
let
fsharpCoreAssembly
=
...
...
tests/fsharp/Compiler/Regressions/NullableOptionalRegressionTests.fs
0 → 100644
浏览文件 @
539d5ab5
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
namespace
FSharp
.
Compiler
.
UnitTests
open
NUnit
.
Framework
open
FSharp
.
Test
.
Utilities
.
Compiler
[<
TestFixture
()
>]
module
NullableOptionalRegressionTests
=
[<
Test
>]
let
``Should compile with generic overloaded nullable methods``
()
=
Fsx
"""
open System
type OverloadMeths =
static member Map(m: 'T option, f) = Option.map f m
static member Map(m: 'T when 'T:null, f) = m |> Option.ofObj |> Option.map f
static member Map(m: 'T Nullable, f) = m |> Option.ofNullable |> Option.map f
[<AllowNullLiteral>]
type Node (child:Node)=
new() = new Node(null)
member val child:Node = child with get,set
let test () =
let parent = Node()
let b1 = OverloadMeths.Map(parent.child, fun x -> x.child)
let c1 = OverloadMeths.Map(b1, fun x -> x.child)
()
"""
|>
withLangVersion50
|>
typecheck
|>
shouldSucceed
|>
ignore
tests/fsharp/FSharpSuite.Tests.fsproj
浏览文件 @
539d5ab5
...
...
@@ -58,6 +58,7 @@
<Compile
Include=
"Compiler\Language\StringConcatOptimizationTests.fs"
/>
<Compile
Include=
"Compiler\Language\ComputationExpressionTests.fs"
/>
<Compile
Include=
"Compiler\Stress\LargeExprTests.fs"
/>
<Compile
Include=
"Compiler\Regressions\NullableOptionalRegressionTests.fs"
/>
<Compile
Include=
"Compiler\Regressions\IndexerRegressionTests.fs"
/>
<Compile
Include=
"Compiler\Regressions\ForInDoMutableRegressionTest.fs"
/>
<Compile
Include=
"Compiler\Libraries\Core\LanguagePrimitives\CastToUnitsTests.fs"
/>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录