Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
f2c528f6
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,发现更多精彩内容 >>
未验证
提交
f2c528f6
编写于
1月 03, 2020
作者:
J
Julien Couvreur
提交者:
GitHub
1月 03, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Treat 0- and 1-tuple symbols as tuples (#40459)
上级
94d1d143
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
82 addition
and
16 deletion
+82
-16
src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Types.cs
...harp/Portable/SymbolDisplay/SymbolDisplayVisitor.Types.cs
+1
-1
src/Compilers/CSharp/Portable/Symbols/Metadata/PE/TupleTypeDecoder.cs
...s/CSharp/Portable/Symbols/Metadata/PE/TupleTypeDecoder.cs
+6
-3
src/Compilers/CSharp/Portable/Symbols/NamedTypeSymbol.cs
src/Compilers/CSharp/Portable/Symbols/NamedTypeSymbol.cs
+1
-1
src/Compilers/CSharp/Portable/Symbols/TypeWithAnnotations.cs
src/Compilers/CSharp/Portable/Symbols/TypeWithAnnotations.cs
+1
-1
src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Tuples.cs
...lers/CSharp/Test/Emit/Attributes/AttributeTests_Tuples.cs
+2
-1
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs
+59
-0
src/Compilers/CSharp/Test/Symbol/Symbols/MissingSpecialMember.cs
...pilers/CSharp/Test/Symbol/Symbols/MissingSpecialMember.cs
+1
-0
src/Compilers/Core/Portable/WellKnownMembers.cs
src/Compilers/Core/Portable/WellKnownMembers.cs
+6
-6
src/Compilers/Core/Portable/WellKnownTypes.cs
src/Compilers/Core/Portable/WellKnownTypes.cs
+5
-3
未找到文件。
src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Types.cs
浏览文件 @
f2c528f6
...
...
@@ -454,7 +454,7 @@ private bool CanUseTupleSyntax(INamedTypeSymbol tupleSymbol)
return
false
;
}
if
(
currentUnderlying
.
Arity
=
=
1
)
if
(
currentUnderlying
.
Arity
<
=
1
)
{
return
false
;
}
...
...
src/Compilers/CSharp/Portable/Symbols/Metadata/PE/TupleTypeDecoder.cs
浏览文件 @
f2c528f6
...
...
@@ -236,11 +236,14 @@ private NamedTypeSymbol DecodeNamedType(NamedTypeSymbol type)
if
(
decodedType
.
IsTupleType
)
{
int
tupleCardinality
=
decodedType
.
TupleElementTypesWithAnnotations
.
Length
;
var
elementNames
=
EatElementNamesIfAvailable
(
tupleCardinality
);
if
(
tupleCardinality
>
0
)
{
var
elementNames
=
EatElementNamesIfAvailable
(
tupleCardinality
);
Debug
.
Assert
(
elementNames
.
IsDefault
||
elementNames
.
Length
==
tupleCardinality
);
Debug
.
Assert
(
elementNames
.
IsDefault
||
elementNames
.
Length
==
tupleCardinality
);
decodedType
=
NamedTypeSymbol
.
CreateTuple
(
decodedType
,
elementNames
);
decodedType
=
NamedTypeSymbol
.
CreateTuple
(
decodedType
,
elementNames
);
}
}
return
decodedType
;
...
...
src/Compilers/CSharp/Portable/Symbols/NamedTypeSymbol.cs
浏览文件 @
f2c528f6
...
...
@@ -1485,7 +1485,7 @@ internal bool IsTupleTypeOfCardinality(out int tupleCardinality)
{
int
arity
=
Arity
;
if
(
arity
>
0
&&
arity
<
ValueTupleRestPosition
)
if
(
arity
>
=
0
&&
arity
<
ValueTupleRestPosition
)
{
tupleCardinality
=
arity
;
return
true
;
...
...
src/Compilers/CSharp/Portable/Symbols/TypeWithAnnotations.cs
浏览文件 @
f2c528f6
...
...
@@ -586,7 +586,7 @@ private static bool IsNonGenericValueType(TypeSymbol type)
{
return
type
.
IsNullableType
();
}
return
type
.
IsValueType
&&
!
type
.
IsTupleType
;
return
type
.
IsValueType
;
}
public
void
AddNullableTransforms
(
ArrayBuilder
<
byte
>
transforms
)
...
...
src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Tuples.cs
浏览文件 @
f2c528f6
...
...
@@ -489,7 +489,8 @@ private void ValidateAttributesOnFields()
// public static ValueTuple Field7;
var
field7
=
_derivedClass
.
GetMember
<
FieldSymbol
>(
"Field7"
);
ValidateTupleNameAttribute
(
field7
.
GetAttributes
(),
expectedTupleNamesAttribute
:
false
);
Assert
.
False
(
field7
.
Type
.
IsTupleType
);
Assert
.
True
(
field7
.
Type
.
IsTupleType
);
Assert
.
Empty
(
field7
.
Type
.
TupleElementTypesWithAnnotations
);
// public static (int e1, int e2, int e3, int e4, int e5, int e6, int e7, int e8, int e9) Field8;
var
field8
=
_derivedClass
.
GetMember
<
FieldSymbol
>(
"Field8"
);
...
...
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs
浏览文件 @
f2c528f6
...
...
@@ -5799,6 +5799,65 @@ public void CreateTupleTypeSymbol_BadArguments()
Assert.Contains(CodeAnalysisResources.TupleElementLocationCountMismatch, e.Message);
}
[Fact, WorkItem(36676, "https://github.com/dotnet/roslyn/issues/36676")]
public void CreateTupleTypeSymbol_WithValueTuple_TupleZero()
{
var tupleComp = CreateCompilationWithMscorlib40(@"
namespace System
{
public struct ValueTuple
{
}
}");
var comp = CSharpCompilation.Create("test", references: new[] { MscorlibRef, tupleComp.ToMetadataReference() });
var vt0 = comp.GetWellKnownType(WellKnownType.System_ValueTuple);
var tupleWithoutNames = comp.CreateTupleTypeSymbol(vt0, ImmutableArray<string>.Empty);
Assert.True(tupleWithoutNames.IsTupleType);
Assert.Equal(SymbolKind.NamedType, tupleWithoutNames.TupleUnderlyingType.Kind);
Assert.Equal("System.ValueTuple", tupleWithoutNames.ToTestDisplayString());
Assert.True(GetTupleElementNames(tupleWithoutNames).IsDefault);
Assert.Empty(ElementTypeNames(tupleWithoutNames));
Assert.Equal(SymbolKind.NamedType, tupleWithoutNames.Kind);
TypeSymbol intType = comp.GetSpecialType(SpecialType.System_Int32);
TypeSymbol stringType = comp.GetSpecialType(SpecialType.System_String);
var vt8 = comp.GetWellKnownType(WellKnownType.System_ValueTuple_TRest)
.Construct(intType, stringType, intType, stringType, intType, stringType, intType, vt0);
Assert.False(vt8.IsTupleType);
Assert.Throws<ArgumentException>(() => comp.CreateTupleTypeSymbol(vt8, default));
}
[Fact, WorkItem(36676, "https://github.com/dotnet/roslyn/issues/36676")]
public void CreateTupleTypeSymbol_WithValueTuple_TupleOne()
{
var tupleComp = CreateCompilationWithMscorlib40(@"
namespace System
{
public struct ValueTuple<T1>
{
public T1 Item1;
public ValueTuple(T1 item1)
{
Item1 = item1;
}
}
}");
var comp = CSharpCompilation.Create("test", references: new[] { MscorlibRef, tupleComp.ToMetadataReference() });
TypeSymbol intType = comp.GetSpecialType(SpecialType.System_Int32);
var vt1 = comp.GetWellKnownType(WellKnownType.System_ValueTuple_T1).Construct(intType);
var tupleWithoutNames = comp.CreateTupleTypeSymbol(vt1, ImmutableArray.Create(new[] { (string)null }));
Assert.Same(vt1, ((Symbols.PublicModel.NonErrorNamedTypeSymbol)tupleWithoutNames).UnderlyingNamedTypeSymbol);
Assert.True(tupleWithoutNames.IsTupleType);
Assert.Equal("System.ValueTuple<System.Int32>", tupleWithoutNames.ToTestDisplayString());
Assert.True(GetTupleElementNames(tupleWithoutNames).IsDefault);
Assert.Equal(new[] { "System.Int32" }, ElementTypeNames(tupleWithoutNames));
}
[Fact]
public void CreateTupleTypeSymbol_WithValueTuple()
{
src/Compilers/CSharp/Test/Symbol/Symbols/MissingSpecialMember.cs
浏览文件 @
f2c528f6
...
...
@@ -612,6 +612,7 @@ public void AllWellKnownTypes()
switch
(
wkt
)
{
case
WellKnownType
.
System_ValueTuple
:
case
WellKnownType
.
System_ValueTuple_T1
:
case
WellKnownType
.
System_ValueTuple_T2
:
case
WellKnownType
.
System_ValueTuple_T3
:
...
...
src/Compilers/Core/Portable/WellKnownMembers.cs
浏览文件 @
f2c528f6
...
...
@@ -2631,31 +2631,31 @@ static WellKnownMembers()
// System_ValueTuple_T5__Item1
(
byte
)
MemberFlags
.
Field
,
// Flags
(
byte
)
WellKnownType
.
System_ValueTuple_T5
,
// DeclaringTypeId
(
byte
)
WellKnownType
.
ExtSentinel
,
(
byte
)(
WellKnownType
.
System_ValueTuple_T5
-
WellKnownType
.
ExtSentinel
),
// DeclaringTypeId
0
,
// Arity
(
byte
)
SignatureTypeCode
.
GenericTypeParameter
,
0
,
// Field Signature
// System_ValueTuple_T5__Item2
(
byte
)
MemberFlags
.
Field
,
// Flags
(
byte
)
WellKnownType
.
System_ValueTuple_T5
,
// DeclaringTypeId
(
byte
)
WellKnownType
.
ExtSentinel
,
(
byte
)(
WellKnownType
.
System_ValueTuple_T5
-
WellKnownType
.
ExtSentinel
),
// DeclaringTypeId
0
,
// Arity
(
byte
)
SignatureTypeCode
.
GenericTypeParameter
,
1
,
// Field Signature
// System_ValueTuple_T5__Item3
(
byte
)
MemberFlags
.
Field
,
// Flags
(
byte
)
WellKnownType
.
System_ValueTuple_T5
,
// DeclaringTypeId
(
byte
)
WellKnownType
.
ExtSentinel
,
(
byte
)(
WellKnownType
.
System_ValueTuple_T5
-
WellKnownType
.
ExtSentinel
),
// DeclaringTypeId
0
,
// Arity
(
byte
)
SignatureTypeCode
.
GenericTypeParameter
,
2
,
// Field Signature
// System_ValueTuple_T5__Item4
(
byte
)
MemberFlags
.
Field
,
// Flags
(
byte
)
WellKnownType
.
System_ValueTuple_T5
,
// DeclaringTypeId
(
byte
)
WellKnownType
.
ExtSentinel
,
(
byte
)(
WellKnownType
.
System_ValueTuple_T5
-
WellKnownType
.
ExtSentinel
),
// DeclaringTypeId
0
,
// Arity
(
byte
)
SignatureTypeCode
.
GenericTypeParameter
,
3
,
// Field Signature
// System_ValueTuple_T5__Item5
(
byte
)
MemberFlags
.
Field
,
// Flags
(
byte
)
WellKnownType
.
System_ValueTuple_T5
,
// DeclaringTypeId
(
byte
)
WellKnownType
.
ExtSentinel
,
(
byte
)(
WellKnownType
.
System_ValueTuple_T5
-
WellKnownType
.
ExtSentinel
),
// DeclaringTypeId
0
,
// Arity
(
byte
)
SignatureTypeCode
.
GenericTypeParameter
,
4
,
// Field Signature
...
...
@@ -2825,7 +2825,7 @@ static WellKnownMembers()
// System_ValueTuple_T_T2_T3_T4_T5__ctor
(
byte
)
MemberFlags
.
Constructor
,
// Flags
(
byte
)
WellKnownType
.
System_ValueTuple_T5
,
// DeclaringTypeId
(
byte
)
WellKnownType
.
ExtSentinel
,
(
byte
)(
WellKnownType
.
System_ValueTuple_T5
-
WellKnownType
.
ExtSentinel
),
// DeclaringTypeId
0
,
// Arity
5
,
// Method Signature
(
byte
)
SignatureTypeCode
.
TypeHandle
,
(
byte
)
SpecialType
.
System_Void
,
// Return Type
...
...
src/Compilers/Core/Portable/WellKnownTypes.cs
浏览文件 @
f2c528f6
...
...
@@ -250,14 +250,15 @@ internal enum WellKnownType
CSharp7Sentinel
=
System_IFormatProvider
,
// all types that were known before CSharp7 should remain above this sentinel
System_ValueTuple
,
System_ValueTuple_T1
,
System_ValueTuple_T2
,
System_ValueTuple_T3
,
System_ValueTuple_T4
,
System_ValueTuple_T5
,
ExtSentinel
,
// Not a real type, just a marker for types above 255 and strictly below 512
System_ValueTuple_T5
,
System_ValueTuple_T6
,
System_ValueTuple_T7
,
System_ValueTuple_TRest
,
...
...
@@ -550,14 +551,15 @@ internal static class WellKnownTypes
"System.IFormatProvider"
,
"System.ValueTuple"
,
"System.ValueTuple`1"
,
"System.ValueTuple`2"
,
"System.ValueTuple`3"
,
"System.ValueTuple`4"
,
"System.ValueTuple`5"
,
""
,
// extension marker
"System.ValueTuple`5"
,
"System.ValueTuple`6"
,
"System.ValueTuple`7"
,
"System.ValueTuple`8"
,
...
...
@@ -675,7 +677,7 @@ public static bool IsWellKnownType(this WellKnownType typeId)
public
static
bool
IsValueTupleType
(
this
WellKnownType
typeId
)
{
Debug
.
Assert
(
typeId
!=
WellKnownType
.
ExtSentinel
);
return
typeId
>=
WellKnownType
.
System_ValueTuple
_T1
&&
typeId
<=
WellKnownType
.
System_ValueTuple_TRest
;
return
typeId
>=
WellKnownType
.
System_ValueTuple
&&
typeId
<=
WellKnownType
.
System_ValueTuple_TRest
;
}
public
static
bool
IsValid
(
this
WellKnownType
typeId
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录