Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
436671f5
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,发现更多精彩内容 >>
未验证
提交
436671f5
编写于
12月 13, 2018
作者:
J
Julien Couvreur
提交者:
GitHub
12月 13, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use Equals to compare array types in attributes (#31741)
上级
6d88f91c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
107 addition
and
1 deletion
+107
-1
src/Compilers/CSharp/Portable/Binder/Binder_Attributes.cs
src/Compilers/CSharp/Portable/Binder/Binder_Attributes.cs
+3
-1
src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
...rp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
+79
-0
src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTuples.vb
src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTuples.vb
+25
-0
未找到文件。
src/Compilers/CSharp/Portable/Binder/Binder_Attributes.cs
浏览文件 @
436671f5
...
...
@@ -625,7 +625,9 @@ private TypeSymbol BindNamedAttributeArgumentType(AttributeArgumentSyntax namedA
{
hasErrors
=
true
;
}
else
if
(
reorderedArgument
.
Kind
==
TypedConstantKind
.
Array
&&
parameter
.
Type
.
TypeKind
==
TypeKind
.
Array
&&
(
TypeSymbol
)
reorderedArgument
.
Type
!=
parameter
.
Type
.
TypeSymbol
)
else
if
(
reorderedArgument
.
Kind
==
TypedConstantKind
.
Array
&&
parameter
.
Type
.
TypeKind
==
TypeKind
.
Array
&&
!((
TypeSymbol
)
reorderedArgument
.
Type
).
Equals
(
parameter
.
Type
.
TypeSymbol
,
TypeCompareKind
.
AllIgnoreOptions
))
{
// NOTE: As in dev11, we don't allow array covariance conversions (presumably, we don't have a way to
// represent the conversion in metadata).
...
...
src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
浏览文件 @
436671f5
...
...
@@ -445,6 +445,85 @@ static void F2(object? w)
Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotation, "?").WithLocation(14, 26));
}
[Fact, WorkItem(31740, "https://github.com/dotnet/roslyn/issues/31740")]
public void Attribute_ArrayWithDifferentNullability()
{
var source =
@"
public class MyAttribute : System.Attribute
{
public MyAttribute(string[] x) { }
}
#nullable enable
[My(new string[] { ""hello"" })]
class C { }
";
var comp = CreateCompilation(source, options: TestOptions.DebugDll);
comp.VerifyDiagnostics();
}
[Fact, WorkItem(31740, "https://github.com/dotnet/roslyn/issues/31740")]
public void Attribute_ArrayWithDifferentNullability2()
{
var source =
@"
public class MyAttribute : System.Attribute
{
public MyAttribute(string[] x) { }
}
#nullable enable
[My(new string[] { null })]
class C { }
";
var comp = CreateCompilation(source, options: TestOptions.DebugDll);
comp.VerifyDiagnostics();
// Expecting a warning. Issue tracked by https://github.com/dotnet/roslyn/issues/23697
}
[Fact, WorkItem(31740, "https://github.com/dotnet/roslyn/issues/31740")]
public void Attribute_ArrayWithDifferentNullability_DynamicAndTupleNames()
{
var source = @"
public class MyAttribute : System.Attribute
{
public MyAttribute((string alice, string)[] x, dynamic[] y, object[] z) { }
}
#nullable enable
[My(new (string, string bob)[] { }, new object[] { }, new dynamic[] { })]
class C { }
";
var comp = CreateCompilation(source, options: TestOptions.DebugDll);
comp.VerifyDiagnostics(
// (7,2): error CS0181: Attribute constructor parameter 'x' has type '(string alice, string)[]', which is not a valid attribute parameter type
// [My(new (string, string bob)[] { }, new object[] { }, new dynamic[] { })]
Diagnostic(ErrorCode.ERR_BadAttributeParamType, "My").WithArguments("x", "(string alice, string)[]").WithLocation(7, 2),
// (7,2): error CS0181: Attribute constructor parameter 'y' has type 'dynamic[]', which is not a valid attribute parameter type
// [My(new (string, string bob)[] { }, new object[] { }, new dynamic[] { })]
Diagnostic(ErrorCode.ERR_BadAttributeParamType, "My").WithArguments("y", "dynamic[]").WithLocation(7, 2)
);
}
[Fact, WorkItem(31740, "https://github.com/dotnet/roslyn/issues/31740")]
public void Attribute_ArrayWithDifferentNullability_Dynamic()
{
var source =
@"
public class MyAttribute : System.Attribute
{
public MyAttribute(dynamic[] y) { }
}
#nullable enable
[My(new object[] { })]
class C { }
";
var comp = CreateCompilation(source, options: TestOptions.DebugDll);
comp.VerifyDiagnostics(
// (7,2): error CS0181: Attribute constructor parameter 'y' has type 'dynamic[]', which is not a valid attribute parameter type
// [My(new object[] { })]
Diagnostic(ErrorCode.ERR_BadAttributeParamType, "My").WithArguments("y", "dynamic[]").WithLocation(7, 2)
);
}
[Fact]
public void NullableAndConditionalOperators()
{
src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTuples.vb
浏览文件 @
436671f5
...
...
@@ -109,6 +109,31 @@ Namespace System
End Namespace
"
<Fact>
Public Sub TupleNamesInArrayInAttribute()
Dim comp = CreateCompilation(
<compilation>
<file name="a.vb"><![CDATA[
Imports System
<My(New (String, bob As String)() { })>
Public Class MyAttribute
Inherits System.Attribute
Public Sub New(x As (alice As String, String)())
End Sub
End Class
]]></file>
</compilation>)
comp.AssertTheseDiagnostics(<errors><![CDATA[
BC30045: Attribute constructor has a parameter of type '(alice As String, String)()', which is not an integral, floating-point or Enum type or one of Object, Char, String, Boolean, System.Type or 1-dimensional array of these types.
<My(New (String, bob As String)() { })>
~~
]]></errors>)
End Sub
<Fact>
Public Sub TupleTypeBinding()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录