Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
ad32a7a6
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,发现更多精彩内容 >>
提交
ad32a7a6
编写于
3月 06, 2015
作者:
N
Neal Gafter
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow VB Shared New to initialize a Shared field of another instance.
Fixes #1028 Closes #1116
上级
56a89273
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
96 addition
and
6 deletion
+96
-6
src/Compilers/Test/Utilities/VisualBasic/TestOptions.vb
src/Compilers/Test/Utilities/VisualBasic/TestOptions.vb
+14
-1
src/Compilers/VisualBasic/Portable/Binding/Binder_Expressions.vb
...pilers/VisualBasic/Portable/Binding/Binder_Expressions.vb
+4
-5
src/Compilers/VisualBasic/Portable/Compilation/VisualBasicCompilation.vb
...isualBasic/Portable/Compilation/VisualBasicCompilation.vb
+6
-0
src/Compilers/VisualBasic/Test/Semantic/Semantics/FieldInitializerBindingTests.vb
...c/Test/Semantic/Semantics/FieldInitializerBindingTests.vb
+72
-0
未找到文件。
src/Compilers/Test/Utilities/VisualBasic/TestOptions.vb
浏览文件 @
ad32a7a6
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
' TODO: Strict Module
Imports
System.Runtime.CompilerServices
Public
Class
TestOptions
Public
Shared
ReadOnly
Script
As
New
VisualBasicParseOptions
(
kind
:
=
SourceCodeKind
.
Script
)
Public
Shared
ReadOnly
Interactive
As
New
VisualBasicParseOptions
(
kind
:
=
SourceCodeKind
.
Interactive
)
...
...
@@ -20,3 +21,15 @@ Public Class TestOptions
Public
Shared
ReadOnly
ReleaseModule
As
New
VisualBasicCompilationOptions
(
OutputKind
.
NetModule
,
optimizationLevel
:
=
OptimizationLevel
.
Release
)
Public
Shared
ReadOnly
ReleaseWinMD
As
New
VisualBasicCompilationOptions
(
OutputKind
.
WindowsRuntimeMetadata
,
optimizationLevel
:
=
OptimizationLevel
.
Release
)
End
Class
Module
TestOptionExtensions
<
Extension
()
>
Public
Function
WithStrictMode
(
options
As
VisualBasicCompilationOptions
)
As
VisualBasicCompilationOptions
Return
options
.
WithFeatures
(
options
.
Features
.
Add
(
"strict"
))
End
Function
<
Extension
()
>
Public
Function
WithStrictMode
(
compilation
As
VisualBasicCompilation
)
As
VisualBasicCompilation
Return
compilation
.
WithOptions
(
compilation
.
Options
.
WithStrictMode
())
End
Function
End
Module
src/Compilers/VisualBasic/Portable/Binding/Binder_Expressions.vb
浏览文件 @
ad32a7a6
...
...
@@ -1551,11 +1551,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
' an LValue. In this case, containingMember will be a LambdaSymbol rather than a symbol for
' constructor.
If
Me
.
ContainingMember
.
ContainingSymbol
Is
field
.
ContainingSymbol
Then
Return
True
End
If
Return
False
' We duplicate a bug in the native compiler for compatibility in non-strict mode
Return
If
(
Me
.
Compilation
.
FeatureStrictEnabled
,
Me
.
ContainingMember
.
ContainingSymbol
Is
field
.
ContainingSymbol
,
Me
.
ContainingMember
.
ContainingSymbol
.
OriginalDefinition
Is
field
.
ContainingSymbol
.
OriginalDefinition
)
End
Function
''' <summary>
...
...
src/Compilers/VisualBasic/Portable/Compilation/VisualBasicCompilation.vb
浏览文件 @
ad32a7a6
...
...
@@ -1820,6 +1820,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Return
New
SyntaxTreeSemanticModel
(
Me
,
DirectCast
(
Me
.
SourceModule
,
SourceModuleSymbol
),
syntaxTree
,
ignoreAccessibility
)
End
Function
Friend
ReadOnly
Property
FeatureStrictEnabled
As
Boolean
Get
Return
Me
.
Feature
(
"strict"
)
IsNot
Nothing
End
Get
End
Property
#End Region
#Region "Diagnostics"
...
...
src/Compilers/VisualBasic/Test/Semantic/Semantics/FieldInitializerBindingTests.vb
浏览文件 @
ad32a7a6
...
...
@@ -1408,6 +1408,78 @@ BC30799: Field 'Clazz.b' has an invalid constant value.
</
errors
>
)
End
Sub
<
Fact
,
WorkItem
(
1028
,
"https://github.com/dotnet/roslyn/issues/1028"
)
>
Sub
WriteOfReadonlySharedMemberOfAnotherInstantiation01
()
Dim
compilation
=
CompilationUtils
.
CreateCompilationWithMscorlib
(
<
compilation
>
<
file
name
=
"a.vb"
>
Class
Foo
(
Of
T
)
Shared
Sub
New
()
Foo
(
Of
Integer
).
X
=
12
Foo
(
Of
Integer
).
Y
=
12
Foo
(
Of
T
).
X
=
12
Foo
(
Of
T
).
Y
=
12
End
Sub
Public
Shared
ReadOnly
X
As
Integer
Public
Shared
ReadOnly
Property
Y
As
Integer
=
0
End
Class
</
file
>
</
compilation
>
,
TestOptions
.
ReleaseDll
)
CompilationUtils
.
AssertTheseDiagnostics
(
compilation
,
<
expected
>
BC30526
:
Property
'Y' is 'ReadOnly'.
Foo
(
Of
Integer
).
Y
=
12
~~~~~~~~~~~~~~~~~~~~~~
</
expected
>
)
CompilationUtils
.
AssertTheseDiagnostics
(
compilation
.
WithStrictMode
(),
<
expected
>
BC30064
:
'ReadOnly' variable cannot be the target of an assignment.
Foo
(
Of
Integer
).
X
=
12
~~~~~~~~~~~~~~~~~
BC30526
:
Property
'Y' is 'ReadOnly'.
Foo
(
Of
Integer
).
Y
=
12
~~~~~~~~~~~~~~~~~~~~~~
</
expected
>
)
End
Sub
<
Fact
,
WorkItem
(
1028
,
"https://github.com/dotnet/roslyn/issues/1028"
)
>
Public
Sub
WriteOfReadonlySharedMemberOfAnotherInstantiation02
()
CompileAndVerify
(
<
compilation
>
<
file
name
=
"a.vb"
>
Imports
System
Module
M1
Sub
Main
()
Console
.
WriteLine
(
Foo
(
Of
Long
).
X
)
Console
.
WriteLine
(
Foo
(
Of
Integer
).
X
)
Console
.
WriteLine
(
Foo
(
Of
String
).
X
)
Console
.
WriteLine
(
Foo
(
Of
Integer
).
X
)
End
Sub
End
Module
Public
Class
Foo
(
Of
T
)
Shared
Sub
New
()
Console
.
WriteLine
(
"Initializing for {0}"
,
GetType
(
T
))
Foo
(
Of
Integer
).
X
=
GetType
(
T
).
Name
End
Sub
Public
Shared
ReadOnly
X
As
String
End
Class
</
file
>
</
compilation
>
,
verify
:
=
False
,
expectedOutput
:
=
"Initializing for System.Int64
Initializing for System.Int32
Int64
Initializing for System.String
String
"
)
End
Sub
#Region "Helpers"
Private
Shared
Function
CompileAndExtractTypeSymbol
(
sources
As
Xml
.
Linq
.
XElement
,
Optional
typeName
As
String
=
"C"
)
As
SourceNamedTypeSymbol
Dim
compilation
=
CompilationUtils
.
CreateCompilationWithMscorlib
(
sources
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录