Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
fa83ec65
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,发现更多精彩内容 >>
提交
fa83ec65
编写于
7月 14, 2016
作者:
V
VSadov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simple type/field binding works
上级
95877bf2
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
428 addition
and
42 deletion
+428
-42
src/Compilers/VisualBasic/Portable/Binding/Binder_Symbols.vb
src/Compilers/VisualBasic/Portable/Binding/Binder_Symbols.vb
+128
-36
src/Compilers/VisualBasic/Portable/Emit/SymbolTranslator.vb
src/Compilers/VisualBasic/Portable/Emit/SymbolTranslator.vb
+6
-1
src/Compilers/VisualBasic/Portable/Errors/Errors.vb
src/Compilers/VisualBasic/Portable/Errors/Errors.vb
+6
-0
src/Compilers/VisualBasic/Portable/Symbols/NamedTypeSymbol.vb
...Compilers/VisualBasic/Portable/Symbols/NamedTypeSymbol.vb
+61
-0
src/Compilers/VisualBasic/Portable/Symbols/Tuples/TupleTypeSymbol.vb
...rs/VisualBasic/Portable/Symbols/Tuples/TupleTypeSymbol.vb
+5
-5
src/Compilers/VisualBasic/Portable/VBResources.Designer.vb
src/Compilers/VisualBasic/Portable/VBResources.Designer.vb
+45
-0
src/Compilers/VisualBasic/Portable/VBResources.resx
src/Compilers/VisualBasic/Portable/VBResources.resx
+15
-0
src/Compilers/VisualBasic/Test/Emit/BasicCompilerEmitTest.vbproj
...pilers/VisualBasic/Test/Emit/BasicCompilerEmitTest.vbproj
+1
-0
src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTuples.vb
src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTuples.vb
+161
-0
未找到文件。
src/Compilers/VisualBasic/Portable/Binding/Binder_Symbols.vb
浏览文件 @
fa83ec65
...
@@ -4,6 +4,7 @@ Imports System.Collections.Generic
...
@@ -4,6 +4,7 @@ Imports System.Collections.Generic
Imports
System.Collections.Immutable
Imports
System.Collections.Immutable
Imports
System.Runtime.InteropServices
Imports
System.Runtime.InteropServices
Imports
System.Threading
Imports
System.Threading
Imports
Microsoft.CodeAnalysis.Collections
Imports
Microsoft.CodeAnalysis.Text
Imports
Microsoft.CodeAnalysis.Text
Imports
Microsoft.CodeAnalysis.VisualBasic.Symbols
Imports
Microsoft.CodeAnalysis.VisualBasic.Symbols
Imports
Microsoft.CodeAnalysis.VisualBasic.Syntax
Imports
Microsoft.CodeAnalysis.VisualBasic.Syntax
...
@@ -341,7 +342,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
...
@@ -341,7 +342,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Dim
diagName
=
GetBaseNamesForDiagnostic
(
typeSyntax
)
Dim
diagName
=
GetBaseNamesForDiagnostic
(
typeSyntax
)
diagInfo
=
NotFound
(
typeSyntax
,
diagName
,
binder
,
diagBag
,
reportedAnError
)
diagInfo
=
NotFound
(
typeSyntax
,
diagName
,
binder
,
diagBag
,
reportedAnError
)
Return
B
inder
.
GetErrorSymbol
(
diagName
,
diagInfo
)
Return
b
inder
.
GetErrorSymbol
(
diagName
,
diagInfo
)
Else
Else
If
lookupResult
.
HasDiagnostic
Then
If
lookupResult
.
HasDiagnostic
Then
Dim
diagName
=
GetBaseNamesForDiagnostic
(
typeSyntax
)
Dim
diagName
=
GetBaseNamesForDiagnostic
(
typeSyntax
)
...
@@ -371,7 +372,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
...
@@ -371,7 +372,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Binder
.
ReportDiagnostic
(
diagBag
,
typeSyntax
,
diagInfo
)
Binder
.
ReportDiagnostic
(
diagBag
,
typeSyntax
,
diagInfo
)
End
If
End
If
Return
B
inder
.
GetErrorSymbol
(
GetBaseNamesForDiagnostic
(
typeSyntax
),
diagInfo
,
ImmutableArray
.
Create
(
Of
Symbol
)(
sym
),
LookupResultKind
.
NotATypeOrNamespace
)
Return
b
inder
.
GetErrorSymbol
(
GetBaseNamesForDiagnostic
(
typeSyntax
),
diagInfo
,
ImmutableArray
.
Create
(
Of
Symbol
)(
sym
),
LookupResultKind
.
NotATypeOrNamespace
)
Else
Else
' When we bind generic type reference, we pass through here with symbols for
' When we bind generic type reference, we pass through here with symbols for
' the generic type definition, each type argument and for the final constructed
' the generic type definition, each type argument and for the final constructed
...
@@ -386,7 +387,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
...
@@ -386,7 +387,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Emit
.
NoPia
.
EmbeddedTypesManager
.
IsValidEmbeddableType
(
DirectCast
(
typeSymbol
,
NamedTypeSymbol
),
typeSyntax
,
diagBag
)
Emit
.
NoPia
.
EmbeddedTypesManager
.
IsValidEmbeddableType
(
DirectCast
(
typeSymbol
,
NamedTypeSymbol
),
typeSyntax
,
diagBag
)
End
If
End
If
B
inder
.
ReportDiagnosticsIfObsolete
(
diagBag
,
sym
,
typeSyntax
)
b
inder
.
ReportDiagnosticsIfObsolete
(
diagBag
,
sym
,
typeSyntax
)
Return
sym
Return
sym
End
If
End
If
...
@@ -596,7 +597,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
...
@@ -596,7 +597,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Binder
.
ReportDiagnostic
(
diagBag
,
typeSyntax
,
diagInfo
)
Binder
.
ReportDiagnostic
(
diagBag
,
typeSyntax
,
diagInfo
)
End
If
End
If
Return
B
inder
.
GetErrorSymbol
(
diagName
,
diagInfo
)
Return
b
inder
.
GetErrorSymbol
(
diagName
,
diagInfo
)
Else
Else
If
lookupResult
.
HasDiagnostic
Then
If
lookupResult
.
HasDiagnostic
Then
If
Not
reportedAnError
Then
If
Not
reportedAnError
Then
...
@@ -608,7 +609,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
...
@@ -608,7 +609,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
' LookupTypeOrNamespaceSyntax can't return more than one symbol.
' LookupTypeOrNamespaceSyntax can't return more than one symbol.
Dim
result
=
lookupResult
.
SingleSymbol
Dim
result
=
lookupResult
.
SingleSymbol
B
inder
.
ReportDiagnosticsIfObsolete
(
diagBag
,
result
,
typeSyntax
)
b
inder
.
ReportDiagnosticsIfObsolete
(
diagBag
,
result
,
typeSyntax
)
Return
result
Return
result
End
If
End
If
Finally
Finally
...
@@ -657,28 +658,16 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
...
@@ -657,28 +658,16 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
lookupResult
.
SetFrom
(
LookupGlobalName
(
DirectCast
(
typeSyntax
,
GlobalNameSyntax
),
binder
))
lookupResult
.
SetFrom
(
LookupGlobalName
(
DirectCast
(
typeSyntax
,
GlobalNameSyntax
),
binder
))
Case
SyntaxKind
.
PredefinedType
Case
SyntaxKind
.
PredefinedType
L
ookupResult
.
SetFrom
(
LookupPredefinedTypeName
(
DirectCast
(
typeSyntax
,
PredefinedTypeSyntax
),
binder
,
diagBag
,
reportedAnError
,
suppressUseSiteError
))
l
ookupResult
.
SetFrom
(
LookupPredefinedTypeName
(
DirectCast
(
typeSyntax
,
PredefinedTypeSyntax
),
binder
,
diagBag
,
reportedAnError
,
suppressUseSiteError
))
Case
SyntaxKind
.
ArrayType
Case
SyntaxKind
.
ArrayType
L
ookupResult
.
SetFrom
(
LookupArrayType
(
DirectCast
(
typeSyntax
,
ArrayTypeSyntax
),
binder
,
diagBag
,
suppressUseSiteError
,
inGetTypeContext
:
=
inGetTypeContext
))
l
ookupResult
.
SetFrom
(
LookupArrayType
(
DirectCast
(
typeSyntax
,
ArrayTypeSyntax
),
binder
,
diagBag
,
suppressUseSiteError
,
inGetTypeContext
:
=
inGetTypeContext
))
Case
SyntaxKind
.
NullableType
Case
SyntaxKind
.
NullableType
L
ookupResult
.
SetFrom
(
LookupNullableType
(
DirectCast
(
typeSyntax
,
NullableTypeSyntax
),
binder
,
diagBag
,
suppressUseSiteError
))
l
ookupResult
.
SetFrom
(
LookupNullableType
(
DirectCast
(
typeSyntax
,
NullableTypeSyntax
),
binder
,
diagBag
,
suppressUseSiteError
))
Case
SyntaxKind
.
TupleType
Case
SyntaxKind
.
TupleType
'PROTOTYPE: tuple binding
lookupResult
.
SetFrom
(
LookupTupleType
(
DirectCast
(
typeSyntax
,
TupleTypeSyntax
),
binder
,
diagBag
,
suppressUseSiteError
,
inGetTypeContext
,
resolvingBaseType
))
' bind the first element for now to prevent crashing
Dim
tupleType
=
DirectCast
(
typeSyntax
,
TupleTypeSyntax
)
LookupTypeOrNamespaceSyntax
(
lookupResult
,
tupleType
.
TupleElements
(
0
).
Type
,
binder
,
diagBag
,
reportedAnError
,
unwrapAliases
,
suppressUseSiteError
,
inGetTypeContext
,
resolvingBaseType
)
Case
Else
Case
Else
Throw
ExceptionUtilities
.
UnexpectedValue
(
typeSyntax
.
Kind
)
Throw
ExceptionUtilities
.
UnexpectedValue
(
typeSyntax
.
Kind
)
...
@@ -690,6 +679,109 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
...
@@ -690,6 +679,109 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End
If
End
If
End
Sub
End
Sub
Private
Shared
Function
LookupTupleType
(
syntax
As
TupleTypeSyntax
,
binder
As
Binder
,
diagnostics
As
DiagnosticBag
,
suppressUseSiteError
As
Boolean
,
inGetTypeContext
As
Boolean
,
resolvingBaseType
As
Boolean
)
As
TypeSymbol
Dim
numElements
As
Integer
=
syntax
.
TupleElements
.
Count
Dim
types
=
ArrayBuilder
(
Of
TypeSymbol
).
GetInstance
(
numElements
)
Dim
locations
=
ArrayBuilder
(
Of
Location
).
GetInstance
(
numElements
)
Dim
elementNames
As
ArrayBuilder
(
Of
String
)
=
Nothing
' set of names already used
Dim
uniqueFieldNames
=
PooledHashSet
(
Of
String
).
GetInstance
()
Dim
countOfExplicitNames
As
Integer
=
0
For
i
As
Integer
=
0
To
numElements
-
1
Dim
argumentSyntax
=
syntax
.
TupleElements
(
i
)
Dim
argumentType
As
TypeSymbol
=
binder
.
BindTypeSyntax
(
argumentSyntax
.
Type
,
diagnostics
,
suppressUseSiteError
,
inGetTypeContext
,
resolvingBaseType
)
types
.
Add
(
argumentType
)
If
argumentType
.
IsRestrictedType
()
Then
Binder
.
ReportDiagnostic
(
diagnostics
,
argumentSyntax
,
ERRID
.
ERR_RestrictedType1
,
argumentType
)
End
If
Dim
name
As
String
=
Nothing
Dim
nameSyntax
As
IdentifierNameSyntax
=
argumentSyntax
.
IdentifierName
If
nameSyntax
IsNot
Nothing
Then
name
=
nameSyntax
.
Identifier
.
ValueText
' validate name if we have one
countOfExplicitNames
+=
1
CheckTupleMemberName
(
binder
,
name
,
i
,
nameSyntax
,
diagnostics
,
uniqueFieldNames
)
locations
.
Add
(
nameSyntax
.
GetLocation
)
Else
locations
.
Add
(
argumentSyntax
.
GetLocation
)
End
If
CollectTupleFieldMemberNames
(
name
,
i
+
1
,
numElements
,
elementNames
)
Next
uniqueFieldNames
.
Free
()
If
countOfExplicitNames
<>
0
AndAlso
countOfExplicitNames
<>
numElements
Then
Binder
.
ReportDiagnostic
(
diagnostics
,
syntax
,
ERRID
.
ERR_TupleExplicitNamesOnAllMembersOrNone
)
End
If
Dim
typesArray
As
ImmutableArray
(
Of
TypeSymbol
)
=
types
.
ToImmutableAndFree
()
Dim
locationsArray
As
ImmutableArray
(
Of
Location
)
=
locations
.
ToImmutableAndFree
()
If
typesArray
.
Length
<
2
Then
'PROTOTYPE: tuples error ID
Dim
diaginfo
=
diagnostics
.
Add
(
ERRID
.
ERR_TupleTooFewElements
,
syntax
.
GetLocation
)
Return
ErrorTypeSymbol
.
UnknownResultType
End
If
Return
TupleTypeSymbol
.
Create
(
syntax
.
GetLocation
,
typesArray
,
locationsArray
,
If
(
elementNames
Is
Nothing
,
Nothing
,
elementNames
.
ToImmutableAndFree
()),
binder
.
Compilation
,
syntax
,
diagnostics
)
End
Function
Private
Shared
Sub
CollectTupleFieldMemberNames
(
name
As
String
,
position
As
Integer
,
tupleSize
As
Integer
,
ByRef
elementNames
As
ArrayBuilder
(
Of
String
))
' add the name to the list
' names would typically all be there Or none at all
' but in case we need to handle this in error cases
If
elementNames
IsNot
Nothing
Then
elementNames
.
Add
(
If
(
name
,
TupleTypeSymbol
.
TupleMemberName
(
position
)))
Else
If
name
IsNot
Nothing
Then
elementNames
=
ArrayBuilder
(
Of
String
).
GetInstance
(
tupleSize
)
For
j
As
Integer
=
1
To
position
-
1
elementNames
.
Add
(
TupleTypeSymbol
.
TupleMemberName
(
j
))
Next
elementNames
.
Add
(
name
)
End
If
End
If
End
Sub
Private
Shared
Function
CheckTupleMemberName
(
binder
As
Binder
,
name
As
String
,
position
As
Integer
,
syntax
As
VisualBasicSyntaxNode
,
diagnostics
As
DiagnosticBag
,
uniqueFieldNames
As
PooledHashSet
(
Of
String
))
As
Boolean
Dim
reserved
As
Integer
=
TupleTypeSymbol
.
IsElementNameReserved
(
name
)
If
reserved
=
0
Then
Binder
.
ReportDiagnostic
(
diagnostics
,
syntax
,
ERRID
.
ERR_TupleReservedMemberNameAnyPosition
,
name
)
Return
False
ElseIf
reserved
>
0
AndAlso
reserved
<>
position
+
1
Then
Binder
.
ReportDiagnostic
(
diagnostics
,
syntax
,
ERRID
.
ERR_TupleReservedMemberName
,
name
,
reserved
)
Return
False
ElseIf
(
Not
uniqueFieldNames
.
Add
(
name
))
Then
Binder
.
ReportDiagnostic
(
diagnostics
,
syntax
,
ERRID
.
ERR_TupleDuplicateMemberName
)
Return
False
End
If
Return
True
End
Function
Private
Shared
Sub
AnalyzeLookupResultForIllegalBaseTypeReferences
(
lookupResult
As
LookupResult
,
Private
Shared
Sub
AnalyzeLookupResultForIllegalBaseTypeReferences
(
lookupResult
As
LookupResult
,
typeSyntax
As
TypeSyntax
,
typeSyntax
As
TypeSyntax
,
binder
As
Binder
,
binder
As
Binder
,
...
@@ -748,9 +840,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
...
@@ -748,9 +840,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Private
Shared
Function
ErrorTypeFromLookupResult
(
name
As
String
,
result
As
LookupResult
,
binder
As
Binder
)
As
ErrorTypeSymbol
Private
Shared
Function
ErrorTypeFromLookupResult
(
name
As
String
,
result
As
LookupResult
,
binder
As
Binder
)
As
ErrorTypeSymbol
If
result
.
Kind
=
LookupResultKind
.
Ambiguous
AndAlso
result
.
HasSingleSymbol
AndAlso
TypeOf
result
.
Diagnostic
Is
AmbiguousSymbolDiagnostic
Then
If
result
.
Kind
=
LookupResultKind
.
Ambiguous
AndAlso
result
.
HasSingleSymbol
AndAlso
TypeOf
result
.
Diagnostic
Is
AmbiguousSymbolDiagnostic
Then
' Special case: set of ambiguous symbols is stored in the diagnostics.
' Special case: set of ambiguous symbols is stored in the diagnostics.
Return
B
inder
.
GetErrorSymbol
(
name
,
result
.
Diagnostic
,
DirectCast
(
result
.
Diagnostic
,
AmbiguousSymbolDiagnostic
).
AmbiguousSymbols
,
result
.
Kind
)
Return
b
inder
.
GetErrorSymbol
(
name
,
result
.
Diagnostic
,
DirectCast
(
result
.
Diagnostic
,
AmbiguousSymbolDiagnostic
).
AmbiguousSymbols
,
result
.
Kind
)
End
If
End
If
Return
B
inder
.
GetErrorSymbol
(
name
,
result
.
Diagnostic
,
result
.
Symbols
.
ToImmutable
(),
result
.
Kind
)
Return
b
inder
.
GetErrorSymbol
(
name
,
result
.
Diagnostic
,
result
.
Symbols
.
ToImmutable
(),
result
.
Kind
)
End
Function
End
Function
''' <summary>
''' <summary>
...
@@ -764,7 +856,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
...
@@ -764,7 +856,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
If
sym
.
IsNamespace
Then
If
sym
.
IsNamespace
Then
Dim
diagInfo
=
New
BadSymbolDiagnostic
(
sym
,
ERRID
.
ERR_UnrecognizedType
)
Dim
diagInfo
=
New
BadSymbolDiagnostic
(
sym
,
ERRID
.
ERR_UnrecognizedType
)
Binder
.
ReportDiagnostic
(
diagBag
,
syntax
,
diagInfo
)
Binder
.
ReportDiagnostic
(
diagBag
,
syntax
,
diagInfo
)
Return
B
inder
.
GetErrorSymbol
(
sym
.
Name
,
diagInfo
,
ImmutableArray
.
Create
(
Of
Symbol
)(
sym
),
LookupResultKind
.
NotATypeOrNamespace
)
Return
b
inder
.
GetErrorSymbol
(
sym
.
Name
,
diagInfo
,
ImmutableArray
.
Create
(
Of
Symbol
)(
sym
),
LookupResultKind
.
NotATypeOrNamespace
)
Else
Else
Return
DirectCast
(
sym
,
TypeSymbol
)
Return
DirectCast
(
sym
,
TypeSymbol
)
End
If
End
If
...
@@ -825,7 +917,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
...
@@ -825,7 +917,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Throw
ExceptionUtilities
.
UnexpectedValue
(
predefinedType
)
Throw
ExceptionUtilities
.
UnexpectedValue
(
predefinedType
)
End
Select
End
Select
Dim
sym
=
B
inder
.
GetSpecialType
(
type
,
node
,
diagBag
,
reportedAnError
,
suppressUseSiteError
)
Dim
sym
=
b
inder
.
GetSpecialType
(
type
,
node
,
diagBag
,
reportedAnError
,
suppressUseSiteError
)
Return
SingleLookupResult
.
Good
(
sym
)
Return
SingleLookupResult
.
Good
(
sym
)
End
Function
End
Function
...
@@ -837,7 +929,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
...
@@ -837,7 +929,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
diagBag
As
DiagnosticBag
,
diagBag
As
DiagnosticBag
,
suppressUseSiteError
As
Boolean
,
suppressUseSiteError
As
Boolean
,
inGetTypeContext
As
Boolean
)
As
SingleLookupResult
inGetTypeContext
As
Boolean
)
As
SingleLookupResult
Dim
elementType
As
TypeSymbol
=
B
inder
.
BindTypeSyntax
(
arrayTypeSyntax
.
ElementType
,
Dim
elementType
As
TypeSymbol
=
b
inder
.
BindTypeSyntax
(
arrayTypeSyntax
.
ElementType
,
diagBag
,
diagBag
,
suppressUseSiteError
:
=
suppressUseSiteError
,
suppressUseSiteError
:
=
suppressUseSiteError
,
inGetTypeContext
:
=
inGetTypeContext
)
inGetTypeContext
:
=
inGetTypeContext
)
...
@@ -851,8 +943,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
...
@@ -851,8 +943,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
binder
As
Binder
,
binder
As
Binder
,
diagBag
As
DiagnosticBag
,
diagBag
As
DiagnosticBag
,
suppressUseSiteError
As
Boolean
)
As
SingleLookupResult
suppressUseSiteError
As
Boolean
)
As
SingleLookupResult
Dim
elementType
As
TypeSymbol
=
B
inder
.
BindTypeSyntax
(
nullableTypeSyntax
.
ElementType
,
diagBag
,
suppressUseSiteError
)
Dim
elementType
As
TypeSymbol
=
b
inder
.
BindTypeSyntax
(
nullableTypeSyntax
.
ElementType
,
diagBag
,
suppressUseSiteError
)
Return
SingleLookupResult
.
Good
(
B
inder
.
CreateNullableOf
(
elementType
,
nullableTypeSyntax
,
nullableTypeSyntax
.
ElementType
,
diagBag
))
Return
SingleLookupResult
.
Good
(
b
inder
.
CreateNullableOf
(
elementType
,
nullableTypeSyntax
,
nullableTypeSyntax
.
ElementType
,
diagBag
))
End
Function
End
Function
''' <summary>
''' <summary>
...
@@ -928,7 +1020,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
...
@@ -928,7 +1020,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
' TODO: Dev10 squiggles type arguments for this error, but Roslyn will squiggle the whole type name.
' TODO: Dev10 squiggles type arguments for this error, but Roslyn will squiggle the whole type name.
' If we want to preserve Dev10 behavior, it should be possible to provide optional location/syntax node
' If we want to preserve Dev10 behavior, it should be possible to provide optional location/syntax node
' for the diagnostic attached to LookupResult.
' for the diagnostic attached to LookupResult.
L
ookupResult
.
SetFrom
(
SingleLookupResult
.
WrongArity
(
lookupResult
.
SingleSymbol
,
l
ookupResult
.
SetFrom
(
SingleLookupResult
.
WrongArity
(
lookupResult
.
SingleSymbol
,
New
BadSymbolDiagnostic
(
lookupResult
.
SingleSymbol
,
ERRID
.
ERR_TypeOrMemberNotGeneric1
,
lookupResult
.
SingleSymbol
)))
New
BadSymbolDiagnostic
(
lookupResult
.
SingleSymbol
,
ERRID
.
ERR_TypeOrMemberNotGeneric1
,
lookupResult
.
SingleSymbol
)))
End
If
End
If
Else
Else
...
@@ -939,11 +1031,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
...
@@ -939,11 +1031,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End
If
End
If
' Construct the type and validate constraints.
' Construct the type and validate constraints.
Dim
constructedType
=
B
inder
.
ConstructAndValidateConstraints
(
Dim
constructedType
=
b
inder
.
ConstructAndValidateConstraints
(
genericType
,
typeArguments
,
genericNameSyntax
,
typeArgumentsSyntax
.
Arguments
,
diagBag
)
genericType
,
typeArguments
,
genericNameSyntax
,
typeArgumentsSyntax
.
Arguments
,
diagBag
)
' Put the constructed type in. Note that this preserves any error associated with the lookupResult.
' Put the constructed type in. Note that this preserves any error associated with the lookupResult.
L
ookupResult
.
ReplaceSymbol
(
constructedType
)
l
ookupResult
.
ReplaceSymbol
(
constructedType
)
End
If
End
If
End
Sub
End
Sub
...
@@ -985,7 +1077,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
...
@@ -985,7 +1077,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Dim
leftSymbol
As
NamespaceOrTypeSymbol
=
DirectCast
(
lookupResult
.
SingleSymbol
,
NamespaceOrTypeSymbol
)
Dim
leftSymbol
As
NamespaceOrTypeSymbol
=
DirectCast
(
lookupResult
.
SingleSymbol
,
NamespaceOrTypeSymbol
)
B
inder
.
ReportDiagnosticsIfObsolete
(
diagBag
,
leftSymbol
,
leftNameSyntax
)
b
inder
.
ReportDiagnosticsIfObsolete
(
diagBag
,
leftSymbol
,
leftNameSyntax
)
lookupResult
.
Clear
()
lookupResult
.
Clear
()
Dim
useSiteDiagnostics
As
HashSet
(
Of
DiagnosticInfo
)
=
Nothing
Dim
useSiteDiagnostics
As
HashSet
(
Of
DiagnosticInfo
)
=
Nothing
...
@@ -1060,7 +1152,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
...
@@ -1060,7 +1152,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Dim
leftSymbol
As
NamespaceOrTypeSymbol
=
DirectCast
(
lookupResult
.
SingleSymbol
,
NamespaceOrTypeSymbol
)
Dim
leftSymbol
As
NamespaceOrTypeSymbol
=
DirectCast
(
lookupResult
.
SingleSymbol
,
NamespaceOrTypeSymbol
)
B
inder
.
ReportDiagnosticsIfObsolete
(
diagBag
,
leftSymbol
,
leftNameSyntax
)
b
inder
.
ReportDiagnosticsIfObsolete
(
diagBag
,
leftSymbol
,
leftNameSyntax
)
' Lookup the generic type.
' Lookup the generic type.
lookupResult
.
Clear
()
lookupResult
.
Clear
()
...
@@ -1087,11 +1179,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
...
@@ -1087,11 +1179,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Return
Return
Else
Else
' Construct the type and validate constraints.
' Construct the type and validate constraints.
Dim
constructedType
=
B
inder
.
ConstructAndValidateConstraints
(
Dim
constructedType
=
b
inder
.
ConstructAndValidateConstraints
(
genericType
,
typeArguments
,
genDottedNameSyntax
,
typeArgumentsSyntax
.
Arguments
,
diagBag
)
genericType
,
typeArguments
,
genDottedNameSyntax
,
typeArgumentsSyntax
.
Arguments
,
diagBag
)
' Note: this preserves any error associated with the generic type, which is what we want.
' Note: this preserves any error associated with the generic type, which is what we want.
L
ookupResult
.
ReplaceSymbol
(
constructedType
)
l
ookupResult
.
ReplaceSymbol
(
constructedType
)
End
If
End
If
End
Sub
End
Sub
...
@@ -1114,7 +1206,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
...
@@ -1114,7 +1206,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Dim
types
As
TypeSymbol
()
=
New
TypeSymbol
(
0
To
arity
-
1
)
{}
Dim
types
As
TypeSymbol
()
=
New
TypeSymbol
(
0
To
arity
-
1
)
{}
For
i
As
Integer
=
0
To
arity
-
1
For
i
As
Integer
=
0
To
arity
-
1
types
(
i
)
=
B
inder
.
BindTypeSyntax
(
typeArgumentsSyntax
.
Arguments
(
i
),
diagBag
,
suppressUseSiteError
)
types
(
i
)
=
b
inder
.
BindTypeSyntax
(
typeArgumentsSyntax
.
Arguments
(
i
),
diagBag
,
suppressUseSiteError
)
Next
Next
Return
types
.
AsImmutableOrNull
()
Return
types
.
AsImmutableOrNull
()
...
...
src/Compilers/VisualBasic/Portable/Emit/SymbolTranslator.vb
浏览文件 @
fa83ec65
...
@@ -120,6 +120,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit
...
@@ -120,6 +120,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit
' Anonymous type being translated
' Anonymous type being translated
If
namedTypeSymbol
.
IsAnonymousType
Then
If
namedTypeSymbol
.
IsAnonymousType
Then
namedTypeSymbol
=
AnonymousTypeManager
.
TranslateAnonymousTypeSymbol
(
namedTypeSymbol
)
namedTypeSymbol
=
AnonymousTypeManager
.
TranslateAnonymousTypeSymbol
(
namedTypeSymbol
)
ElseIf
(
namedTypeSymbol
.
IsTupleType
)
Then
Debug
.
Assert
(
Not
needDeclaration
)
namedTypeSymbol
=
namedTypeSymbol
.
TupleUnderlyingType
End
If
End
If
' Substitute error types with a special singleton object.
' Substitute error types with a special singleton object.
...
@@ -234,6 +237,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit
...
@@ -234,6 +237,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit
)
As
Microsoft
.
Cci
.
IFieldReference
)
As
Microsoft
.
Cci
.
IFieldReference
Debug
.
Assert
(
fieldSymbol
Is
fieldSymbol
.
OriginalDefinition
OrElse
Debug
.
Assert
(
fieldSymbol
Is
fieldSymbol
.
OriginalDefinition
OrElse
Not
fieldSymbol
.
Equals
(
fieldSymbol
.
OriginalDefinition
))
Not
fieldSymbol
.
Equals
(
fieldSymbol
.
OriginalDefinition
))
If
fieldSymbol
.
IsTupleField
Then
fieldSymbol
=
fieldSymbol
.
TupleUnderlyingField
End
If
Me
.
ProcessReferencedSymbol
(
fieldSymbol
)
Me
.
ProcessReferencedSymbol
(
fieldSymbol
)
...
@@ -473,6 +479,5 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit
...
@@ -473,6 +479,5 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Emit
Friend
Overloads
Function
Translate
(
symbol
As
ArrayTypeSymbol
)
As
Microsoft
.
Cci
.
IArrayTypeReference
Friend
Overloads
Function
Translate
(
symbol
As
ArrayTypeSymbol
)
As
Microsoft
.
Cci
.
IArrayTypeReference
Return
symbol
Return
symbol
End
Function
End
Function
End
Class
End
Class
End
Namespace
End
Namespace
src/Compilers/VisualBasic/Portable/Errors/Errors.vb
浏览文件 @
fa83ec65
...
@@ -1687,6 +1687,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
...
@@ -1687,6 +1687,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
ERR_OptionMustBeAbsolutePath
=
37257
ERR_OptionMustBeAbsolutePath
=
37257
ERR_TupleExplicitNamesOnAllMembersOrNone
=
37258
ERR_TupleTooFewElements
=
37259
ERR_TupleReservedMemberNameAnyPosition
=
37260
ERR_TupleReservedMemberName
=
37261
ERR_TupleDuplicateMemberName
=
37262
ERR_LastPlusOne
ERR_LastPlusOne
...
...
src/Compilers/VisualBasic/Portable/Symbols/NamedTypeSymbol.vb
浏览文件 @
fa83ec65
...
@@ -1237,5 +1237,66 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
...
@@ -1237,5 +1237,66 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
#End Region
#End Region
''' <summary>
''' Verify if the given type can be used to back a tuple type
''' and return cardinality of that tuple type in <paramref name="tupleCardinality"/>.
''' </summary>
''' <param name="tupleCardinality">If method returns true, contains cardinality of the compatible tuple type.</param>
''' <returns></returns>
Public
Overrides
Function
IsTupleCompatible
(
<
Out
>
ByRef
tupleCardinality
As
Integer
)
As
Boolean
If
IsTupleType
Then
tupleCardinality
=
0
Return
False
End
If
' Should this be optimized for perf (caching for VT<0> to VT<7>, etc.)?
If
(
Not
IsUnboundGenericType
AndAlso
ContainingSymbol
?
.
Kind
=
SymbolKind
.
Namespace
AndAlso
ContainingNamespace
.
ContainingNamespace
?
.
IsGlobalNamespace
=
True
AndAlso
Name
=
TupleTypeSymbol
.
TupleTypeName
AndAlso
ContainingNamespace
.
Name
=
MetadataHelpers
.
SystemString
)
Then
Dim
arity
=
Me
.
Arity
If
arity
>
0
AndAlso
arity
<
TupleTypeSymbol
.
RestPosition
Then
tupleCardinality
=
arity
Return
True
ElseIf
arity
=
TupleTypeSymbol
.
RestPosition
AndAlso
Not
IsDefinition
Then
' Skip through "Rest" extensions
Dim
typeToCheck
As
TypeSymbol
=
Me
Dim
levelsOfNesting
As
Integer
=
0
Do
levelsOfNesting
+=
1
typeToCheck
=
DirectCast
(
typeToCheck
,
NamedTypeSymbol
).
TypeArgumentsNoUseSiteDiagnostics
(
TupleTypeSymbol
.
RestPosition
-
1
)
Loop
While
typeToCheck
.
OriginalDefinition
=
Me
.
OriginalDefinition
AndAlso
Not
typeToCheck
.
IsDefinition
If
typeToCheck
.
IsTupleType
Then
Dim
underlying
=
typeToCheck
.
TupleUnderlyingType
If
underlying
.
Arity
=
TupleTypeSymbol
.
RestPosition
AndAlso
underlying
.
OriginalDefinition
<>
Me
.
OriginalDefinition
Then
tupleCardinality
=
0
Return
False
End
If
tupleCardinality
=
(
TupleTypeSymbol
.
RestPosition
-
1
)
*
levelsOfNesting
+
typeToCheck
.
TupleElementTypes
.
Length
Return
True
End
If
arity
=
If
(
TryCast
(
typeToCheck
,
NamedTypeSymbol
)
?
.
Arity
,
0
)
If
arity
>
0
AndAlso
arity
<
TupleTypeSymbol
.
RestPosition
AndAlso
typeToCheck
.
IsTupleCompatible
(
tupleCardinality
)
Then
Debug
.
Assert
(
tupleCardinality
<
TupleTypeSymbol
.
RestPosition
)
tupleCardinality
+=
(
TupleTypeSymbol
.
RestPosition
-
1
)
*
levelsOfNesting
Return
True
End
If
End
If
End
If
tupleCardinality
=
0
Return
False
End
Function
End
Class
End
Class
End
Namespace
End
Namespace
src/Compilers/VisualBasic/Portable/Symbols/Tuples/TupleTypeSymbol.vb
浏览文件 @
fa83ec65
...
@@ -478,8 +478,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
...
@@ -478,8 +478,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
End
Function
End
Function
Private
Shared
Function
NumberOfValueTuples
(
numElements
As
Integer
,
<
Out
()
>
ByRef
remainder
As
Integer
)
As
Integer
Private
Shared
Function
NumberOfValueTuples
(
numElements
As
Integer
,
<
Out
()
>
ByRef
remainder
As
Integer
)
As
Integer
remainder
=
(
numElements
-
1
)
Mod
TupleTypeSymbol
.
RestPosition
-
1
+
1
remainder
=
(
numElements
-
1
)
Mod
(
RestPosition
-
1
)
+
1
Return
(
numElements
-
1
)
\
TupleTypeSymbol
.
RestPosition
-
1
+
1
Return
(
numElements
-
1
)
\
(
RestPosition
-
1
)
+
1
End
Function
End
Function
Private
Shared
Function
GetTupleUnderlyingType
(
elementTypes
As
ImmutableArray
(
Of
TypeSymbol
),
syntax
As
VisualBasicSyntaxNode
,
compilation
As
VisualBasicCompilation
,
diagnostics
As
DiagnosticBag
)
As
NamedTypeSymbol
Private
Shared
Function
GetTupleUnderlyingType
(
elementTypes
As
ImmutableArray
(
Of
TypeSymbol
),
syntax
As
VisualBasicSyntaxNode
,
compilation
As
VisualBasicCompilation
,
diagnostics
As
DiagnosticBag
)
As
NamedTypeSymbol
...
@@ -493,7 +493,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
...
@@ -493,7 +493,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Binder
.
ReportUseSiteError
(
diagnostics
,
syntax
,
wellKnownType
)
Binder
.
ReportUseSiteError
(
diagnostics
,
syntax
,
wellKnownType
)
End
If
End
If
Dim
namedTypeSymbol
As
NamedTypeSymbol
=
wellKnownType
.
Construct
(
ImmutableArray
.
Create
(
Of
TypeSymbol
)(
elementTypes
,
(
chainLength
-
1
)
*
TupleTypeSymbol
.
RestPosition
-
1
,
remainder
))
Dim
namedTypeSymbol
As
NamedTypeSymbol
=
wellKnownType
.
Construct
(
ImmutableArray
.
Create
(
Of
TypeSymbol
)(
elementTypes
,
(
chainLength
-
1
)
*
(
TupleTypeSymbol
.
RestPosition
-
1
)
,
remainder
))
Dim
[
loop
]
As
Integer
=
chainLength
-
1
Dim
[
loop
]
As
Integer
=
chainLength
-
1
If
[
loop
]
>
0
Then
If
[
loop
]
>
0
Then
Dim
wellKnownType2
As
NamedTypeSymbol
=
compilation
.
GetWellKnownType
(
TupleTypeSymbol
.
GetTupleType
(
TupleTypeSymbol
.
RestPosition
))
Dim
wellKnownType2
As
NamedTypeSymbol
=
compilation
.
GetWellKnownType
(
TupleTypeSymbol
.
GetTupleType
(
TupleTypeSymbol
.
RestPosition
))
...
@@ -502,7 +502,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
...
@@ -502,7 +502,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Binder
.
ReportUseSiteError
(
diagnostics
,
syntax
,
wellKnownType2
)
Binder
.
ReportUseSiteError
(
diagnostics
,
syntax
,
wellKnownType2
)
End
If
End
If
Do
Do
Dim
typeArguments
As
ImmutableArray
(
Of
TypeSymbol
)
=
ImmutableArray
.
Create
(
Of
TypeSymbol
)(
elementTypes
,
(
[
loop
]
-
1
)
*
TupleTypeSymbol
.
RestPosition
-
1
,
TupleTypeSymbol
.
RestPosition
-
1
).
Add
(
namedTypeSymbol
)
Dim
typeArguments
As
ImmutableArray
(
Of
TypeSymbol
)
=
ImmutableArray
.
Create
(
Of
TypeSymbol
)(
elementTypes
,
(
[
loop
]
-
1
)
*
(
TupleTypeSymbol
.
RestPosition
-
1
)
,
TupleTypeSymbol
.
RestPosition
-
1
).
Add
(
namedTypeSymbol
)
namedTypeSymbol
=
wellKnownType2
.
Construct
(
typeArguments
)
namedTypeSymbol
=
wellKnownType2
.
Construct
(
typeArguments
)
[
loop
]
-=
1
[
loop
]
-=
1
Loop
While
[
loop
]
>
0
Loop
While
[
loop
]
>
0
...
@@ -661,7 +661,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
...
@@ -661,7 +661,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Dim
field
=
DirectCast
(
member
,
FieldSymbol
)
Dim
field
=
DirectCast
(
member
,
FieldSymbol
)
Dim
tupleFieldIndex
=
currentFieldsForElements
.
IndexOf
(
field
,
ReferenceEqualityComparer
.
Instance
)
Dim
tupleFieldIndex
=
currentFieldsForElements
.
IndexOf
(
field
,
ReferenceEqualityComparer
.
Instance
)
If
tupleFieldIndex
=
0
Then
If
tupleFieldIndex
>
=
0
Then
' This Is a tuple backing field
' This Is a tuple backing field
Dim
FieldSymbol
=
field
.
AsMember
(
currentUnderlying
)
Dim
FieldSymbol
=
field
.
AsMember
(
currentUnderlying
)
...
...
src/Compilers/VisualBasic/Portable/VBResources.Designer.vb
浏览文件 @
fa83ec65
...
@@ -10325,6 +10325,51 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
...
@@ -10325,6 +10325,51 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Get
End Get
End Property
End Property
'''<summary>
''' Looks up a localized string similar to Tuple member names must be unique..
'''</summary>
Friend ReadOnly Property ERR_TupleDuplicateMemberName() As String
Get
Return ResourceManager.GetString("ERR_TupleDuplicateMemberName", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to Tuple member names must all be provided, if any one is provided..
'''</summary>
Friend ReadOnly Property ERR_TupleExplicitNamesOnAllMembersOrNone() As String
Get
Return ResourceManager.GetString("ERR_TupleExplicitNamesOnAllMembersOrNone", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to Tuple member name '{0}' is only allowed at position {1}..
'''</summary>
Friend ReadOnly Property ERR_TupleReservedMemberName() As String
Get
Return ResourceManager.GetString("ERR_TupleReservedMemberName", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to Tuple membername '{0}' is disallowed at any position..
'''</summary>
Friend ReadOnly Property ERR_TupleReservedMemberNameAnyPosition() As String
Get
Return ResourceManager.GetString("ERR_TupleReservedMemberNameAnyPosition", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to Tuple must contain at least two elements..
'''</summary>
Friend ReadOnly Property ERR_TupleTooFewElements() As String
Get
Return ResourceManager.GetString("ERR_TupleTooFewElements", resourceCulture)
End Get
End Property
'''<summary>
'''<summary>
''' Looks up a localized string similar to Operator '{0}' must have two parameters..
''' Looks up a localized string similar to Operator '{0}' must have two parameters..
'''</summary>
'''</summary>
...
...
src/Compilers/VisualBasic/Portable/VBResources.resx
浏览文件 @
fa83ec65
...
@@ -5367,4 +5367,19 @@
...
@@ -5367,4 +5367,19 @@
<data
name=
"ERR_OptionMustBeAbsolutePath"
xml:space=
"preserve"
>
<data
name=
"ERR_OptionMustBeAbsolutePath"
xml:space=
"preserve"
>
<value>
Option '{0}' must be an absolute path.
</value>
<value>
Option '{0}' must be an absolute path.
</value>
</data>
</data>
<data
name=
"ERR_TupleDuplicateMemberName"
xml:space=
"preserve"
>
<value>
Tuple member names must be unique.
</value>
</data>
<data
name=
"ERR_TupleExplicitNamesOnAllMembersOrNone"
xml:space=
"preserve"
>
<value>
Tuple member names must all be provided, if any one is provided.
</value>
</data>
<data
name=
"ERR_TupleReservedMemberName"
xml:space=
"preserve"
>
<value>
Tuple member name '{0}' is only allowed at position {1}.
</value>
</data>
<data
name=
"ERR_TupleReservedMemberNameAnyPosition"
xml:space=
"preserve"
>
<value>
Tuple membername '{0}' is disallowed at any position.
</value>
</data>
<data
name=
"ERR_TupleTooFewElements"
xml:space=
"preserve"
>
<value>
Tuple must contain at least two elements.
</value>
</data>
</root>
</root>
src/Compilers/VisualBasic/Test/Emit/BasicCompilerEmitTest.vbproj
浏览文件 @
fa83ec65
...
@@ -98,6 +98,7 @@
...
@@ -98,6 +98,7 @@
<Compile
Include=
"CodeGen\CodeGenAsyncTests.vb"
/>
<Compile
Include=
"CodeGen\CodeGenAsyncTests.vb"
/>
<Compile
Include=
"CodeGen\CodeGenClosureLambdaTests.vb"
/>
<Compile
Include=
"CodeGen\CodeGenClosureLambdaTests.vb"
/>
<Compile
Include=
"CodeGen\CodeGenCollectionInitializer.vb"
/>
<Compile
Include=
"CodeGen\CodeGenCollectionInitializer.vb"
/>
<Compile
Include=
"CodeGen\CodeGenTuples.vb"
/>
<Compile
Include=
"CodeGen\CodeGenConstLocal.vb"
/>
<Compile
Include=
"CodeGen\CodeGenConstLocal.vb"
/>
<Compile
Include=
"CodeGen\CodeGenDelegateCreation.vb"
/>
<Compile
Include=
"CodeGen\CodeGenDelegateCreation.vb"
/>
<Compile
Include=
"CodeGen\CodeGenEvents.vb"
/>
<Compile
Include=
"CodeGen\CodeGenEvents.vb"
/>
...
...
src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTuples.vb
0 → 100644
浏览文件 @
fa83ec65
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports
Microsoft.CodeAnalysis
Imports
Microsoft.CodeAnalysis.Test.Utilities
Imports
Microsoft.CodeAnalysis.Text
Imports
Microsoft.CodeAnalysis.VisualBasic
Imports
Microsoft.CodeAnalysis.VisualBasic.Symbols
Imports
Microsoft.CodeAnalysis.VisualBasic.Syntax
Imports
Microsoft.CodeAnalysis.VisualBasic.UnitTests.Emit
Imports
Roslyn.Test.Utilities
Namespace
Microsoft.CodeAnalysis.VisualBasic.UnitTests
Public
Class
CodeGenTuples
Inherits
BasicTestBase
<
Fact
()
>
Public
Sub
TupleTypeBinding
()
Dim
verifier
=
CompileAndVerify
(
<
compilation
>
<
file
name
=
"a.vb"
>
Imports
System
Module
C
Sub
Main
()
Dim
t
as
(
Integer
,
Integer
)
console
.
writeline
(
t
)
End
Sub
End
Module
Namespace
System
Structure
ValueTuple
(
Of
T1
,
T2
)
Public
Overrides
Function
ToString
()
As
String
Return
"hello"
End
Function
End
Structure
End
Namespace
</
file
>
</
compilation
>
,
expectedOutput
:
=<
!
[
CDATA
[
hello
]]
>
)
verifier
.
VerifyIL
(
"C.Main"
,
<
!
[
CDATA
[
{
//
Code
size
12
(
0
xc
)
.
maxstack
1
.
locals
init
(
System
.
ValueTuple
(
Of
Integer
,
Integer
)
V_0
)
//
t
IL_0000
:
ldloc
.
0
IL_0001
:
box
"System.ValueTuple(Of Integer, Integer)"
IL_0006
:
call
"Sub System.Console.WriteLine(Object)"
IL_000b
:
ret
}
]]
>
)
End
Sub
<
Fact
()
>
Public
Sub
TupleFieldBinding
()
Dim
verifier
=
CompileAndVerify
(
<
compilation
>
<
file
name
=
"a.vb"
>
Imports
System
Module
C
Sub
Main
()
Dim
t
as
(
Integer
,
Integer
)
t
.
Item1
=
42
t
.
Item2
=
t
.
Item1
console
.
writeline
(
t
.
Item2
)
End
Sub
End
Module
Namespace
System
Structure
ValueTuple
(
Of
T1
,
T2
)
Public
Item1
As
T1
Public
Item2
As
T2
End
Structure
End
Namespace
</
file
>
</
compilation
>
,
expectedOutput
:
=<
!
[
CDATA
[
42
]]
>
)
verifier
.
VerifyIL
(
"C.Main"
,
<
!
[
CDATA
[
{
//
Code
size
34
(
0
x22
)
.
maxstack
2
.
locals
init
(
System
.
ValueTuple
(
Of
Integer
,
Integer
)
V_0
)
//
t
IL_0000
:
ldloca
.
s
V_0
IL_0002
:
ldc
.
i4
.
s
42
IL_0004
:
stfld
"System.ValueTuple(Of Integer, Integer).Item1 As Integer"
IL_0009
:
ldloca
.
s
V_0
IL_000b
:
ldloc
.
0
IL_000c
:
ldfld
"System.ValueTuple(Of Integer, Integer).Item1 As Integer"
IL_0011
:
stfld
"System.ValueTuple(Of Integer, Integer).Item2 As Integer"
IL_0016
:
ldloc
.
0
IL_0017
:
ldfld
"System.ValueTuple(Of Integer, Integer).Item2 As Integer"
IL_001c
:
call
"Sub System.Console.WriteLine(Integer)"
IL_0021
:
ret
}
]]
>
)
End
Sub
<
Fact
()
>
Public
Sub
TupleNamedFieldBinding
()
Dim
verifier
=
CompileAndVerify
(
<
compilation
>
<
file
name
=
"a.vb"
>
Imports
System
Module
C
Sub
Main
()
Dim
t
As
(
a
As
Integer
,
b
As
Integer
)
t
.
a
=
42
t
.
b
=
t
.
a
Console
.
WriteLine
(
t
.
b
)
End
Sub
End
Module
Namespace
System
Structure
ValueTuple
(
Of
T1
,
T2
)
Public
Item1
As
T1
Public
Item2
As
T2
End
Structure
End
Namespace
</
file
>
</
compilation
>
,
expectedOutput
:
=<
!
[
CDATA
[
42
]]
>
)
verifier
.
VerifyIL
(
"C.Main"
,
<
!
[
CDATA
[
{
//
Code
size
34
(
0
x22
)
.
maxstack
2
.
locals
init
(
System
.
ValueTuple
(
Of
Integer
,
Integer
)
V_0
)
//
t
IL_0000
:
ldloca
.
s
V_0
IL_0002
:
ldc
.
i4
.
s
42
IL_0004
:
stfld
"System.ValueTuple(Of Integer, Integer).Item1 As Integer"
IL_0009
:
ldloca
.
s
V_0
IL_000b
:
ldloc
.
0
IL_000c
:
ldfld
"System.ValueTuple(Of Integer, Integer).Item1 As Integer"
IL_0011
:
stfld
"System.ValueTuple(Of Integer, Integer).Item2 As Integer"
IL_0016
:
ldloc
.
0
IL_0017
:
ldfld
"System.ValueTuple(Of Integer, Integer).Item2 As Integer"
IL_001c
:
call
"Sub System.Console.WriteLine(Integer)"
IL_0021
:
ret
}
]]
>
)
End
Sub
End
Class
End
Namespace
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录