Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
28a42d8b
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,发现更多精彩内容 >>
提交
28a42d8b
编写于
10月 12, 2016
作者:
V
VSadov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
New with tuple syntax
上级
37773774
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
155 addition
and
15 deletion
+155
-15
src/Compilers/VisualBasic/Portable/Binding/Binder_ObjectInitializer.vb
.../VisualBasic/Portable/Binding/Binder_ObjectInitializer.vb
+2
-0
src/Compilers/VisualBasic/Portable/Errors/Errors.vb
src/Compilers/VisualBasic/Portable/Errors/Errors.vb
+1
-0
src/Compilers/VisualBasic/Portable/Parser/ParseExpression.vb
src/Compilers/VisualBasic/Portable/Parser/ParseExpression.vb
+4
-0
src/Compilers/VisualBasic/Portable/Parser/Parser.vb
src/Compilers/VisualBasic/Portable/Parser/Parser.vb
+4
-0
src/Compilers/VisualBasic/Portable/VBResources.Designer.vb
src/Compilers/VisualBasic/Portable/VBResources.Designer.vb
+27
-9
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
+76
-2
src/Compilers/VisualBasic/Test/Syntax/Parser/ParseExpression.vb
...mpilers/VisualBasic/Test/Syntax/Parser/ParseExpression.vb
+38
-4
未找到文件。
src/Compilers/VisualBasic/Portable/Binding/Binder_ObjectInitializer.vb
浏览文件 @
28a42d8b
...
...
@@ -315,6 +315,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
resultKind
=
LookupResultKind
.
NotCreatable
errorReported
=
True
Case
TypeKind
.
Array
' the diagnostic that AsNew cannot be used to init arrays has already been reported
' so there is nothing to do here.
...
...
src/Compilers/VisualBasic/Portable/Errors/Errors.vb
浏览文件 @
28a42d8b
...
...
@@ -1706,6 +1706,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
ERR_TupleElementNamesAttributeMissing
=
37268
ERR_ExplicitTupleElementNamesAttribute
=
37269
ERR_TupleLiteralDisallowsTypeChar
=
37270
ERR_NewWithTupleTypeSyntax
=
37271
' Available 37270
ERR_DuplicateProcDefWithDifferentTupleNames2
=
37271
...
...
src/Compilers/VisualBasic/Portable/Parser/ParseExpression.vb
浏览文件 @
28a42d8b
...
...
@@ -864,6 +864,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
' Here we are after parsing " New Blah(a1,a2)"
If
Type
.
Kind
=
SyntaxKind
.
TupleType
Then
Type
=
ReportSyntaxError
(
Type
,
ERRID
.
ERR_NewWithTupleTypeSyntax
)
End
If
Dim
FromToken
As
KeywordSyntax
=
Nothing
If
TryTokenAsContextualKeyword
(
CurrentToken
,
SyntaxKind
.
FromKeyword
,
FromToken
)
Then
...
...
src/Compilers/VisualBasic/Portable/Parser/Parser.vb
浏览文件 @
28a42d8b
...
...
@@ -2252,6 +2252,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax
Else
typeName
=
ParseTypeName
()
If
typeName
.
Kind
=
SyntaxKind
.
TupleType
Then
typeName
=
ReportSyntaxError
(
typeName
,
ERRID
.
ERR_NewWithTupleTypeSyntax
)
End
If
If
CurrentToken
.
Kind
=
SyntaxKind
.
OpenParenToken
Then
' New <Type> ( <Arguments> )
newArguments
=
ParseParenthesizedArguments
()
...
...
src/Compilers/VisualBasic/Portable/VBResources.Designer.vb
浏览文件 @
28a42d8b
...
...
@@ -7800,6 +7800,15 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Get
End Property
'''<summary>
''' Looks up a localized string similar to 'New' cannot be used with tuple type. Use a tuple literal expression instead..
'''</summary>
Friend ReadOnly Property ERR_NewWithTupleTypeSyntax() As String
Get
Return ResourceManager.GetString("ERR_NewWithTupleTypeSyntax", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to Next control variable does not match For loop control variable '{0}'..
'''</summary>
...
...
@@ -10389,11 +10398,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Property
'''<summary>
''' Looks up a localized string similar to Tuple
member
names must be unique..
''' Looks up a localized string similar to Tuple
element
names must be unique..
'''</summary>
Friend ReadOnly Property ERR_TupleDuplicate
Member
Name() As String
Friend ReadOnly Property ERR_TupleDuplicate
Element
Name() As String
Get
Return ResourceManager.GetString("ERR_TupleDuplicate
Member
Name", resourceCulture)
Return ResourceManager.GetString("ERR_TupleDuplicate
Element
Name", resourceCulture)
End Get
End Property
...
...
@@ -10407,20 +10416,29 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Property
'''<summary>
''' Looks up a localized string similar to Tuple member name '{0}' is only allowed at position {1}..
''' Looks up a localized string similar to Type characters cannot be used in tuple literals..
'''</summary>
Friend ReadOnly Property ERR_TupleLiteralDisallowsTypeChar() As String
Get
Return ResourceManager.GetString("ERR_TupleLiteralDisallowsTypeChar", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to Tuple element name '{0}' is only allowed at position {1}..
'''</summary>
Friend ReadOnly Property ERR_TupleReserved
Member
Name() As String
Friend ReadOnly Property ERR_TupleReserved
Element
Name() As String
Get
Return ResourceManager.GetString("ERR_TupleReserved
Member
Name", resourceCulture)
Return ResourceManager.GetString("ERR_TupleReserved
Element
Name", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to Tuple
member
name '{0}' is disallowed at any position..
''' Looks up a localized string similar to Tuple
element
name '{0}' is disallowed at any position..
'''</summary>
Friend ReadOnly Property ERR_TupleReserved
Member
NameAnyPosition() As String
Friend ReadOnly Property ERR_TupleReserved
Element
NameAnyPosition() As String
Get
Return ResourceManager.GetString("ERR_TupleReserved
Member
NameAnyPosition", resourceCulture)
Return ResourceManager.GetString("ERR_TupleReserved
Element
NameAnyPosition", resourceCulture)
End Get
End Property
...
...
src/Compilers/VisualBasic/Portable/VBResources.resx
浏览文件 @
28a42d8b
...
...
@@ -3166,6 +3166,9 @@
<data
name=
"ERR_TupleLiteralDisallowsTypeChar"
xml:space=
"preserve"
>
<value>
Type characters cannot be used in tuple literals.
</value>
</data>
<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_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
浏览文件 @
28a42d8b
...
...
@@ -1031,17 +1031,45 @@ Module C
t.a17 = 42
t.a12 = t.a17
console.writeline(t.a12)
TestArray()
TestNullable()
End Sub
Sub TestArray()
Dim t = New (a1 as Integer, a2 as Integer, a3 as Integer, a4 as integer,
a5 as integer, a6 as integer, a7 as integer, a8 as integer,
a9 as integer, a10 as Integer, a11 as Integer, a12 as Integer,
a13 as integer, a14 as integer, a15 as integer, a16 as integer,
a17 as integer, a18 as integer)() {Nothing}
t(0).a17 = 42
t(0).a12 = t(0).a17
console.writeline(t(0).a12)
End Sub
Sub TestNullable()
Dim t as New (a1 as Integer, a2 as Integer, a3 as Integer, a4 as integer,
a5 as integer, a6 as integer, a7 as integer, a8 as integer,
a9 as integer, a10 as Integer, a11 as Integer, a12 as Integer,
a13 as integer, a14 as integer, a15 as integer, a16 as integer,
a17 as integer, a18 as integer)?
console.writeline(t.HasValue)
End Sub
End Module
</file>
</compilation>, expectedOutput:=<![CDATA[
42
42
False
]]>, additionalRefs:=s_valueTupleRefs)
verifier.VerifyIL("C.Main", <![CDATA[
{
// Code size
64 (0x40
)
// Code size
74 (0x4a
)
.maxstack 2
.locals init (System.ValueTuple(Of Integer, Integer, Integer, Integer, Integer, Integer, Integer, (Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer)) V_0) //t
IL_0000: ldloca.s V_0
...
...
@@ -1060,11 +1088,57 @@ End Module
IL_0030: ldfld "System.ValueTuple(Of Integer, Integer, Integer, Integer, Integer, Integer, Integer, (Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer)).Rest As (Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer)"
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: ret
IL_003f: call "Sub C.TestArray()"
IL_0044: call "Sub C.Testullable()"
IL_0049: ret
}
]]>)
End Sub
<Fact>
Public Sub TupleNewLongErr()
Dim comp = CreateCompilationWithMscorlibAndVBRuntime(
<compilation>
<file name="a.vb"><![CDATA[
Imports System
Module C
Sub Main()
Dim t = New (a1 as Integer, a2 as Integer, a3 as Integer, a4 as integer,
a5 as integer, a6 as integer, a7 as integer, a8 as integer,
a9 as integer, a10 as Integer, a11 as Integer, a12 as String,
a13 as integer, a14 as integer, a15 as integer, a16 as integer,
a17 as integer, a18 as integer)
console.writeline(t.a12.Length)
Dim t1 As New (a1 as Integer, a2 as Integer, a3 as Integer, a4 as integer,
a5 as integer, a6 as integer, a7 as integer, a8 as integer,
a9 as integer, a10 as Integer, a11 as Integer, a12 as String,
a13 as integer, a14 as integer, a15 as integer, a16 as integer,
a17 as integer, a18 as integer)
console.writeline(t1.a12.Length)
End Sub
End Module
]]></file>
</compilation>, additionalRefs:=s_valueTupleRefs)
' should not complain about missing constructor
comp.AssertTheseDiagnostics(
<errors>
BC37271: 'New' cannot be used with tuple type. Use a tuple literal expression instead.
Dim t = New (a1 as Integer, a2 as Integer, a3 as Integer, a4 as integer,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BC37271: 'New' cannot be used with tuple type. Use a tuple literal expression instead.
Dim t1 As New (a1 as Integer, a2 as Integer, a3 as Integer, a4 as integer,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
</errors>)
End Sub
<Fact>
Public Sub TupleLiteralBinding()
...
...
src/Compilers/VisualBasic/Test/Syntax/Parser/ParseExpression.vb
浏览文件 @
28a42d8b
...
...
@@ -424,12 +424,46 @@ ToString]]>.Value)
expr
=
ParseExpression
(
"New Moo() From{1,2,3}"
)
Assert
.
Equal
(
SyntaxKind
.
ObjectCreationExpression
,
expr
.
Kind
)
End
Sub
expr
=
ParseExpression
(
"New (A, B)"
)
Assert
.
Equal
(
SyntaxKind
.
ObjectCreationExpression
,
expr
.
Kind
)
<
Fact
>
Public
Sub
ParseNewTuple
()
ParseAndVerify
(
<
!
[
CDATA
[
Module
Module1
Sub
Main
()
Dim
x
=
New
(
A
,
B
)
Dim
y
=
New
(
A
,
B
)()
Dim
y
=
New
(
A
As
Integer
,
B
$
)
End
Sub
End
Module
]]
>
,
<
errors
>
<
error
id
=
"37271"
message
=
"'New' cannot be used with tuple type. Use a tuple literal expression instead."
start
=
"87"
end
=
"93"
/>
<
error
id
=
"37271"
message
=
"'New' cannot be used with tuple type. Use a tuple literal expression instead."
start
=
"126"
End
=
"132"
/>
<
error
id
=
"37271"
message
=
"'New' cannot be used with tuple type. Use a tuple literal expression instead."
start
=
"167"
End
=
"185"
/>
</
errors
>
)
expr
=
ParseExpression
(
"New (A as Integer, B as integer)(1, 2)"
)
Assert
.
Equal
(
SyntaxKind
.
ObjectCreationExpression
,
expr
.
Kind
)
ParseAndVerify
(
<
!
[
CDATA
[
Module
Module1
Sub
Main
()
Dim
x
As
New
(
A
,
B
)
Dim
y
As
New
(
A
,
B
)()
Dim
y
As
New
(
A
As
Integer
,
B
$
)
End
Sub
Public
Function
Bar
()
As
(
Alice
As
(
Alice
As
Integer
,
Bob
As
Integer
)(),
Bob
As
Integer
)
' this is actually ok, since it is an array
Return
(
New
(
Integer
,
Integer
)()
{(
4
,
5
)},
5
)
End
Function
End
Module
]]
>
,
<
errors
>
<
error
id
=
"37271"
message
=
"'New' cannot be used with tuple type. Use a tuple literal expression instead."
start
=
"88"
end
=
"94"
/>
<
error
id
=
"37271"
message
=
"'New' cannot be used with tuple type. Use a tuple literal expression instead."
start
=
"128"
end
=
"134"
/>
<
error
id
=
"37271"
message
=
"'New' cannot be used with tuple type. Use a tuple literal expression instead."
start
=
"170"
end
=
"188"
/>
</
errors
>
)
End
Sub
<
Fact
>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录