Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
4fa6e3fe
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4fa6e3fe
编写于
1月 31, 2017
作者:
J
Julien Couvreur
提交者:
GitHub
1月 31, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add test for null-coalescing operator on nullable tuples with names (#16857)
上级
cb9b7d9e
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
85 addition
and
0 deletion
+85
-0
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs
+85
-0
未找到文件。
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs
浏览文件 @
4fa6e3fe
...
@@ -16913,6 +16913,91 @@ public void M()
...
@@ -16913,6 +16913,91 @@ public void M()
Assert.Equal("(System.Int32 a, dynamic c) x2", x2.ToTestDisplayString());
Assert.Equal("(System.Int32 a, dynamic c) x2", x2.ToTestDisplayString());
}
}
[Fact]
[WorkItem(16825, "https://github.com/dotnet/roslyn/issues/16825")]
public void NullCoalesingOperatorWithTupleNames()
{
// See section 7.13 of the spec, regarding the null-coalescing operator
var source = @"
public class C
{
public void M()
{
(int a, int b)? nab = (1, 2);
(int a, int c)? nac = (1, 3);
var x1 = nab ?? nac; // (a, b)?
var x2 = nab ?? nac.Value; // (a, b)
var x3 = new C() ?? nac; // C
var x4 = new D() ?? nac; // (a, c)?
var x5 = nab != null ? nab : nac; // (a, )?
var x6 = nab ?? (a: 1, c: 3); // (a, b)
var x7 = nab ?? (a: 1, c: 3); // (a, b)
var x8 = new C() ?? (a: 1, c: 3); // C
var x9 = new D() ?? (a: 1, c: 3); // (a, c)
var x6double = nab ?? (d: 1.1, c: 3); // (a, c)
}
public static implicit operator C((int, int) x) { throw null; }
}
public class D
{
public static implicit operator (int d1, int d2) (D x) { throw null; }
}
";
var comp = CreateCompilationWithMscorlib(source, references: s_valueTupleRefs);
comp.VerifyDiagnostics(
// (16,32): warning CS8123: The tuple element name 'c' is ignored because a different name is specified by the target type '(int a, int b)'.
// var x6 = nab ?? (a: 1, c: 3); // (a, b)?
Diagnostic(ErrorCode.WRN_TupleLiteralNameMismatch, "c: 3").WithArguments("c", "(int a, int b)").WithLocation(16, 32),
// (17,32): warning CS8123: The tuple element name 'c' is ignored because a different name is specified by the target type '(int a, int b)'.
// var x7 = nab ?? (a: 1, c: 3); // (a, b)
Diagnostic(ErrorCode.WRN_TupleLiteralNameMismatch, "c: 3").WithArguments("c", "(int a, int b)").WithLocation(17, 32),
// (18,30): warning CS8123: The tuple element name 'a' is ignored because a different name is specified by the target type '(int, int)'.
// var x8 = new C() ?? (a: 1, c: 3); // C
Diagnostic(ErrorCode.WRN_TupleLiteralNameMismatch, "a: 1").WithArguments("a", "(int, int)").WithLocation(18, 30),
// (18,36): warning CS8123: The tuple element name 'c' is ignored because a different name is specified by the target type '(int, int)'.
// var x8 = new C() ?? (a: 1, c: 3); // C
Diagnostic(ErrorCode.WRN_TupleLiteralNameMismatch, "c: 3").WithArguments("c", "(int, int)").WithLocation(18, 36)
);
var tree = comp.SyntaxTrees.First();
var model = comp.GetSemanticModel(tree);
var nodes = tree.GetCompilationUnitRoot().DescendantNodes();
var x1 = model.GetDeclaredSymbol(nodes.OfType<VariableDeclaratorSyntax>().ElementAt(2));
Assert.Equal("(System.Int32 a, System.Int32 b)? x1", x1.ToTestDisplayString());
var x2 = model.GetDeclaredSymbol(nodes.OfType<VariableDeclaratorSyntax>().ElementAt(3));
Assert.Equal("(System.Int32 a, System.Int32 b) x2", x2.ToTestDisplayString());
var x3 = model.GetDeclaredSymbol(nodes.OfType<VariableDeclaratorSyntax>().ElementAt(4));
Assert.Equal("C x3", x3.ToTestDisplayString());
var x4 = model.GetDeclaredSymbol(nodes.OfType<VariableDeclaratorSyntax>().ElementAt(5));
Assert.Equal("(System.Int32 a, System.Int32 c)? x4", x4.ToTestDisplayString());
var x5 = model.GetDeclaredSymbol(nodes.OfType<VariableDeclaratorSyntax>().ElementAt(6));
Assert.Equal("(System.Int32 a, System.Int32)? x5", x5.ToTestDisplayString());
var x6 = model.GetDeclaredSymbol(nodes.OfType<VariableDeclaratorSyntax>().ElementAt(7));
Assert.Equal("(System.Int32 a, System.Int32 b) x6", x6.ToTestDisplayString());
var x7 = model.GetDeclaredSymbol(nodes.OfType<VariableDeclaratorSyntax>().ElementAt(8));
Assert.Equal("(System.Int32 a, System.Int32 b) x7", x7.ToTestDisplayString());
var x8 = model.GetDeclaredSymbol(nodes.OfType<VariableDeclaratorSyntax>().ElementAt(9));
Assert.Equal("C x8", x8.ToTestDisplayString());
var x9 = model.GetDeclaredSymbol(nodes.OfType<VariableDeclaratorSyntax>().ElementAt(10));
Assert.Equal("(System.Int32 a, System.Int32 c) x9", x9.ToTestDisplayString());
var x6double = model.GetDeclaredSymbol(nodes.OfType<VariableDeclaratorSyntax>().ElementAt(11));
Assert.Equal("(System.Double d, System.Int32 c) x6double", x6double.ToTestDisplayString());
}
[Fact]
[Fact]
public void TernaryTypeInferenceWithNoNames()
public void TernaryTypeInferenceWithNoNames()
{
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录