Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
3007969f
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,发现更多精彩内容 >>
提交
3007969f
编写于
10月 13, 2016
作者:
V
VSadov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ValueTuple should derive from ValueType or an error.
上级
28a42d8b
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
321 addition
and
16 deletion
+321
-16
src/Compilers/CSharp/Portable/Emitter/Model/PEModuleBuilder.cs
...ompilers/CSharp/Portable/Emitter/Model/PEModuleBuilder.cs
+2
-1
src/Compilers/VisualBasic/Portable/Emit/SymbolTranslator.vb
src/Compilers/VisualBasic/Portable/Emit/SymbolTranslator.vb
+21
-1
src/Compilers/VisualBasic/Portable/Errors/Errors.vb
src/Compilers/VisualBasic/Portable/Errors/Errors.vb
+1
-0
src/Compilers/VisualBasic/Portable/Symbols/Tuples/TupleTypeSymbol.vb
...rs/VisualBasic/Portable/Symbols/Tuples/TupleTypeSymbol.vb
+3
-13
src/Compilers/VisualBasic/Portable/VBResources.Designer.vb
src/Compilers/VisualBasic/Portable/VBResources.Designer.vb
+9
-0
src/Compilers/VisualBasic/Portable/VBResources.resx
src/Compilers/VisualBasic/Portable/VBResources.resx
+3
-0
src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTuples.vb
src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTuples.vb
+282
-1
未找到文件。
src/Compilers/CSharp/Portable/Emitter/Model/PEModuleBuilder.cs
浏览文件 @
3007969f
...
...
@@ -898,7 +898,8 @@ private void CheckTupleUnderlying(NamedTypeSymbol namedTypeSymbol, SyntaxNode sy
// but if it does happen we should make it a failure.
// NOTE: declaredBase could be null for interfaces
var
declaredBase
=
namedTypeSymbol
.
BaseTypeNoUseSiteDiagnostics
;
if
(
declaredBase
?.
SpecialType
!=
SpecialType
.
System_ValueType
&&
declaredBase
?.
IsErrorType
()
!=
true
)
if
(
declaredBase
==
null
||
(
declaredBase
.
SpecialType
!=
SpecialType
.
System_ValueType
&&
!
declaredBase
.
IsErrorType
()))
{
// Try to decrease noise by not complaining about the same type over and over again.
if
(
_reportedErrorTypesMap
.
Add
(
namedTypeSymbol
))
...
...
src/Compilers/VisualBasic/Portable/Emit/SymbolTranslator.vb
浏览文件 @
3007969f
...
...
@@ -13,7 +13,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit
' TODO: Need to estimate amount of elements for this map and pass that value to the constructor.
Protected
ReadOnly
m_AssemblyOrModuleSymbolToModuleRefMap
As
New
ConcurrentDictionary
(
Of
Symbol
,
Microsoft
.
Cci
.
IModuleReference
)()
Private
ReadOnly
_genericInstanceMap
As
New
ConcurrentDictionary
(
Of
Symbol
,
Object
)()
Private
ReadOnly
_reportedErrorTypesMap
As
New
ConcurrentSet
(
Of
Error
TypeSymbol
)()
Private
ReadOnly
_reportedErrorTypesMap
As
New
ConcurrentSet
(
Of
TypeSymbol
)()
Private
ReadOnly
_embeddedTypesManagerOpt
As
NoPia
.
EmbeddedTypesManager
Public
Overrides
ReadOnly
Property
EmbeddedTypesManagerOpt
As
NoPia
.
EmbeddedTypesManager
...
...
@@ -119,6 +119,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit
ElseIf
namedTypeSymbol
.
IsTupleType
Then
Debug
.
Assert
(
Not
needDeclaration
)
namedTypeSymbol
=
namedTypeSymbol
.
TupleUnderlyingType
CheckTupleUnderlying
(
namedTypeSymbol
,
syntaxNodeOpt
,
diagnostics
)
End
If
' Substitute error types with a special singleton object.
...
...
@@ -201,6 +203,24 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit
Return
namedTypeSymbol
End
Function
Private
Sub
CheckTupleUnderlying
(
namedTypeSymbol
As
NamedTypeSymbol
,
syntaxNodeOpt
As
SyntaxNode
,
diagnostics
As
DiagnosticBag
)
' check that underlying type of a ValueTuple is indeed a value type (or error)
' this should never happen, in theory,
' but if it does happen we should make it a failure.
' NOTE: declaredBase could be null for interfaces
Dim
declaredBase
=
namedTypeSymbol
.
BaseTypeNoUseSiteDiagnostics
If
declaredBase
Is
Nothing
OrElse
(
declaredBase
.
SpecialType
<>
SpecialType
.
System_ValueType
AndAlso
Not
declaredBase
.
IsErrorType
())
Then
' Try to decrease noise by not complaining about the same type over and over again.
If
(
_reportedErrorTypesMap
.
Add
(
namedTypeSymbol
))
Then
diagnostics
.
Add
(
New
VBDiagnostic
(
ErrorFactory
.
ErrorInfo
(
ERRID
.
ERR_PredefinedValueTupleTypeMustBeStruct
,
namedTypeSymbol
.
MetadataName
),
If
(
syntaxNodeOpt
Is
Nothing
,
NoLocation
.
Singleton
,
syntaxNodeOpt
.
GetLocation
())))
End
If
End
If
End
Sub
Friend
Overloads
Function
Translate
(
[
param
]
As
TypeParameterSymbol
)
As
Microsoft
.
Cci
.
IGenericParameterReference
Debug
.
Assert
(
param
Is
param
.
OriginalDefinition
)
Return
[
param
]
...
...
src/Compilers/VisualBasic/Portable/Errors/Errors.vb
浏览文件 @
3007969f
...
...
@@ -1707,6 +1707,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
ERR_ExplicitTupleElementNamesAttribute
=
37269
ERR_TupleLiteralDisallowsTypeChar
=
37270
ERR_NewWithTupleTypeSyntax
=
37271
ERR_PredefinedValueTupleTypeMustBeStruct
=
37272
' Available 37270
ERR_DuplicateProcDefWithDifferentTupleNames2
=
37271
...
...
src/Compilers/VisualBasic/Portable/Symbols/Tuples/TupleTypeSymbol.vb
浏览文件 @
3007969f
...
...
@@ -68,18 +68,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
End
Get
End
Property
Public
Overrides
ReadOnly
Property
IsReferenceType
As
Boolean
Get
Return
Not
Me
.
_underlyingType
.
IsErrorType
()
AndAlso
Me
.
_underlyingType
.
IsReferenceType
End
Get
End
Property
Public
Overrides
ReadOnly
Property
IsValueType
As
Boolean
Get
Return
Me
.
_underlyingType
.
IsErrorType
()
OrElse
Me
.
_underlyingType
.
IsValueType
End
Get
End
Property
Public
Overrides
ReadOnly
Property
IsImplicitlyDeclared
As
Boolean
Get
Return
False
...
...
@@ -122,7 +110,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Public
Overrides
ReadOnly
Property
TypeKind
As
TypeKind
Get
Return
If
(
Me
.
_underlyingType
.
TypeKind
=
TypeKind
.
Class
,
TypeKind
.
Class
,
TypeKind
.
Struct
)
' From the language perspective tuple is a value type
' composed of its underlying elements
Return
TypeKind
.
Struct
End
Get
End
Property
...
...
src/Compilers/VisualBasic/Portable/VBResources.Designer.vb
浏览文件 @
3007969f
...
...
@@ -9117,6 +9117,15 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Get
End Property
'''<summary>
''' Looks up a localized string similar to Predefined type '{0}' must be a structure..
'''</summary>
Friend ReadOnly Property ERR_PredefinedValueTupleTypeMustBeStruct() As String
Get
Return ResourceManager.GetString("ERR_PredefinedValueTupleTypeMustBeStruct", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to SecurityAction value '{0}' is invalid for PrincipalPermission attribute..
'''</summary>
...
...
src/Compilers/VisualBasic/Portable/VBResources.resx
浏览文件 @
3007969f
...
...
@@ -3169,6 +3169,9 @@
<data
name=
"ERR_NewWithTupleTypeSyntax"
xml:space=
"preserve"
>
<value>
'New' cannot be used with tuple type. Use a tuple literal expression instead.
</value>
</data>
<data
name=
"ERR_PredefinedValueTupleTypeMustBeStruct"
xml:space=
"preserve"
>
<value>
Predefined type '{0}' must be a structure.
</value>
</data>
<data
name=
"ERR_ExtensionMethodUncallable1"
xml:space=
"preserve"
>
<value>
Extension method '{0}' has type constraints that can never be satisfied.
</value>
</data>
...
...
src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTuples.vb
浏览文件 @
3007969f
...
...
@@ -51,6 +51,19 @@ namespace System.Runtime.CompilerServices
End Namespace
"
ReadOnly s_tupleattributes As String = "
namespace System.Runtime.CompilerServices
<AttributeUsage(AttributeTargets.Field Or AttributeTargets.Parameter Or AttributeTargets.Property Or AttributeTargets.ReturnValue Or AttributeTargets.Class Or AttributeTargets.Struct )>
public class TupleElementNamesAttribute : Inherits Attribute
public Sub New(transformNames As String())
End Sub
End Class
End Namespace
"
ReadOnly s_trivial3uple As String = "
Namespace System
Public Structure ValueTuple(Of T1, T2, T3)
...
...
@@ -1089,7 +1102,7 @@ False
IL_0035: ldfld "System.ValueTuple(Of Integer, Integer, Integer, Integer, Integer, Integer, Integer, (Integer, Integer, Integer, Integer)).Item5 As Integer"
IL_003a: call "Sub System.Console.WriteLine(Integer)"
IL_003f: call "Sub C.TestArray()"
IL_0044: call "Sub C.Testullable()"
IL_0044: call "Sub C.Test
N
ullable()"
IL_0049: ret
}
]]>)
...
...
@@ -15549,6 +15562,117 @@ BC30402: 'evtTest3' cannot implement event 'evtTest2' on interface 'I1' because
</errors>)
End Sub
<WorkItem(11689, "https://github.com/dotnet/roslyn/issues/11689")>
<Fact>
Public Sub ValueTupleNotStruct0()
Dim comp = CreateCompilationWithMscorlibAndVBRuntime(
<compilation name="Tuples">
<file name="a.vb">
class C
Shared Sub Main()
Dim x as (a As Integer, b As String)
x.Item1 = 1
x.b = "2"
' by the language rules tuple x is definitely assigned
' since all its elements are definitely assigned
System.Console.WriteLine(x)
end sub
end class
namespace System
public class ValueTuple(Of T1, T2)
public Item1 as T1
public Item2 as T2
public Sub New(item1 as T1 , item2 as T2 )
Me.Item1 = item1
Me.Item2 = item2
end sub
End class
end Namespace
<%= s_tupleattributes %>
</file>
</compilation>,
options:=TestOptions.DebugExe)
comp.AssertTheseEmitDiagnostics(
<errors>
BC37272: Predefined type 'ValueTuple`2' must be a structure.
Dim x as (a As Integer, b As String)
~
</errors>)
End Sub
<WorkItem(11689, "https://github.com/dotnet/roslyn/issues/11689")>
<Fact>
Public Sub ValueTupleNotStruct1()
Dim comp = CreateCompilationWithMscorlibAndVBRuntime(
<compilation name="Tuples">
<file name="a.vb">
class C
Shared Sub Main()
Dim x = (1,2,3,4,5,6,7,8,9)
System.Console.WriteLine(x)
end sub
end class
namespace System
public class ValueTuple(Of T1, T2)
public Item1 as T1
public Item2 as T2
public Sub New(item1 as T1 , item2 as T2 )
Me.Item1 = item1
Me.Item2 = item2
end sub
End class
public class ValueTuple(Of T1, T2, T3, T4, T5, T6, T7, TRest)
public Item1 As T1
public Item2 As T2
public Item3 As T3
public Item4 As T4
public Item5 As T5
public Item6 As T6
public Item7 As T7
public Rest As TRest
public Sub New(item1 As T1, item2 As T2, item3 As T3, item4 As T4, item5 As T5, item6 As T6, item7 As T7, rest As TRest)
Item1 = item1
Item2 = item2
Item3 = item3
Item4 = item4
Item5 = item5
Item6 = item6
Item7 = item7
Rest = rest
end Sub
End Class
end Namespace
<%= s_tupleattributes %>
</file>
</compilation>,
options:=TestOptions.DebugExe)
comp.AssertTheseEmitDiagnostics(
<errors>
BC37272: Predefined type 'ValueTuple`2' must be a structure.
Dim x = (1,2,3,4,5,6,7,8,9)
~
BC37272: Predefined type 'ValueTuple`8' must be a structure.
Dim x = (1,2,3,4,5,6,7,8,9)
~
</errors>)
End Sub
<Fact>
Public Sub ConversionToBase()
Dim compilation1 = CompilationUtils.CreateCompilationWithMscorlib(
...
...
@@ -15582,6 +15706,163 @@ BC33030: Conversion operators cannot convert from a base type.
</errors>)
End Sub
<WorkItem(11689, "https://github.com/dotnet/roslyn/issues/11689")>
<Fact>
Public Sub ValueTupleNotStruct2()
Dim comp = CreateCompilationWithMscorlibAndVBRuntime(
<compilation name="Tuples">
<file name="a.vb">
class C
Shared Sub Main()
end sub
Shared Sub Test2(arg as (a As Integer, b As Integer))
End Sub
end class
namespace System
public class ValueTuple(Of T1, T2)
public Item1 as T1
public Item2 as T2
public Sub New(item1 as T1 , item2 as T2 )
Me.Item1 = item1
Me.Item2 = item2
end sub
End class
end Namespace
<%= s_tupleattributes %>
</file>
</compilation>,
options:=TestOptions.DebugExe)
comp.AssertTheseEmitDiagnostics(
<errors>
BC37272: Predefined type 'ValueTuple`2' must be a structure.
</errors>)
End Sub
<WorkItem(11689, "https://github.com/dotnet/roslyn/issues/11689")>
<Fact>
Public Sub ValueTupleNotStruct2i()
Dim comp = CreateCompilationWithMscorlibAndVBRuntime(
<compilation name="Tuples">
<file name="a.vb">
class C
Shared Sub Main()
end sub
Shared Sub Test2(arg as (a As Integer, b As Integer))
End Sub
end class
namespace System
public interface ValueTuple(Of T1, T2)
End Interface
end Namespace
<%= s_tupleattributes %>
</file>
</compilation>,
options:=TestOptions.DebugExe)
comp.AssertTheseEmitDiagnostics(
<errors>
BC37272: Predefined type 'ValueTuple`2' must be a structure.
</errors>)
End Sub
<WorkItem(11689, "https://github.com/dotnet/roslyn/issues/11689")>
<Fact>
Public Sub ValueTupleNotStruct3()
Dim comp = CreateCompilationWithMscorlibAndVBRuntime(
<compilation name="Tuples">
<file name="a.vb">
class C
Shared Sub Main()
Dim x as (a As Integer, b As String)() = Nothing
' by the language rules tuple x is definitely assigned
' since all its elements are definitely assigned
System.Console.WriteLine(x)
end sub
end class
namespace System
public class ValueTuple(Of T1, T2)
public Item1 as T1
public Item2 as T2
public Sub New(item1 as T1 , item2 as T2 )
Me.Item1 = item1
Me.Item2 = item2
end sub
End class
end Namespace
<%= s_tupleattributes %>
</file>
</compilation>,
options:=TestOptions.DebugExe)
comp.AssertTheseEmitDiagnostics(
<errors>
BC37272: Predefined type 'ValueTuple`2' must be a structure.
Dim x as (a As Integer, b As String)() = Nothing
~
</errors>)
End Sub
<WorkItem(11689, "https://github.com/dotnet/roslyn/issues/11689")>
<Fact>
Public Sub ValueTupleNotStruct4()
Dim comp = CreateCompilationWithMscorlibAndVBRuntime(
<compilation name="Tuples">
<file name="a.vb">
class C
Shared Sub Main()
end sub
Shared Function Test2()as (a As Integer, b As Integer)
End Function
end class
namespace System
public class ValueTuple(Of T1, T2)
public Item1 as T1
public Item2 as T2
public Sub New(item1 as T1 , item2 as T2 )
Me.Item1 = item1
Me.Item2 = item2
end sub
End class
end Namespace
<%= s_tupleattributes %>
</file>
</compilation>,
options:=TestOptions.DebugExe)
comp.AssertTheseEmitDiagnostics(
<errors>
BC37272: Predefined type 'ValueTuple`2' must be a structure.
Shared Function Test2()as (a As Integer, b As Integer)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
</errors>)
End Sub
<Fact>
Public Sub IsBaseOf_WithoutCustomModifiers()
' The IL is from this code, but with modifiers
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录