Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
f6b9c6eb
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,体验更适合开发者的 AI 搜索 >>
提交
f6b9c6eb
编写于
9月 30, 2017
作者:
N
Neal Gafter
提交者:
GitHub
9月 30, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Ensure partial method implementation is completed when needed (#22414)
Fixes #18348
上级
2cb56d2c
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
121 addition
and
9 deletion
+121
-9
src/Compilers/CSharp/Portable/Compilation/CSharpCompilation.cs
...ompilers/CSharp/Portable/Compilation/CSharpCompilation.cs
+0
-9
src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs
...arp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs
+13
-0
src/Compilers/CSharp/Test/Symbol/Compilation/GetUnusedImportDirectivesTests.cs
...Test/Symbol/Compilation/GetUnusedImportDirectivesTests.cs
+56
-0
src/Compilers/VisualBasic/Test/Semantic/Semantics/GetUnusedImportDirectivesTests.vb
...Test/Semantic/Semantics/GetUnusedImportDirectivesTests.vb
+52
-0
未找到文件。
src/Compilers/CSharp/Portable/Compilation/CSharpCompilation.cs
浏览文件 @
f6b9c6eb
...
...
@@ -2201,15 +2201,6 @@ private static bool IsDefinedOrImplementedInSourceTree(Symbol symbol, SyntaxTree
return
true
;
}
if
(
symbol
.
IsPartialDefinition
())
{
MethodSymbol
implementationPart
=
((
MethodSymbol
)
symbol
).
PartialImplementationPart
;
if
((
object
)
implementationPart
!=
null
)
{
return
implementationPart
.
IsDefinedInSourceTree
(
tree
,
span
);
}
}
if
(
symbol
.
Kind
==
SymbolKind
.
Method
&&
symbol
.
IsImplicitlyDeclared
&&
((
MethodSymbol
)
symbol
).
MethodKind
==
MethodKind
.
Constructor
)
{
// Include implicitly declared constructor if containing type is included
...
...
src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs
浏览文件 @
f6b9c6eb
...
...
@@ -9,6 +9,7 @@
using
Microsoft.CodeAnalysis.CSharp.Symbols
;
using
Microsoft.CodeAnalysis.CSharp.Syntax
;
using
Microsoft.CodeAnalysis.PooledObjects
;
using
Microsoft.CodeAnalysis.Text
;
using
Roslyn.Utilities
;
namespace
Microsoft.CodeAnalysis.CSharp.Symbols
...
...
@@ -996,6 +997,18 @@ internal override void ForceComplete(SourceLocation locationOpt, CancellationTok
base
.
ForceComplete
(
locationOpt
,
cancellationToken
);
}
internal
override
bool
IsDefinedInSourceTree
(
SyntaxTree
tree
,
TextSpan
?
definedWithinSpan
,
CancellationToken
cancellationToken
=
default
(
CancellationToken
))
{
// Since only the declaring (and not the implementing) part of a partial method appears in the member
// list, we need to ensure we complete the implementation part when needed.
return
base
.
IsDefinedInSourceTree
(
tree
,
definedWithinSpan
,
cancellationToken
)
||
this
.
SourcePartialImplementation
?.
IsDefinedInSourceTree
(
tree
,
definedWithinSpan
,
cancellationToken
)
==
true
;
}
internal
override
void
AfterAddingTypeMembersChecks
(
ConversionsBase
conversions
,
DiagnosticBag
diagnostics
)
{
// Check constraints on return type and parameters. Note: Dev10 uses the
...
...
src/Compilers/CSharp/Test/Symbol/Compilation/GetUnusedImportDirectivesTests.cs
浏览文件 @
f6b9c6eb
...
...
@@ -375,5 +375,61 @@ public void UnusedUsingScript()
// using System;
Diagnostic
(
ErrorCode
.
HDN_UnusedUsingDirective
,
"using System;"
));
}
[
Fact
,
WorkItem
(
18348
,
"https://github.com/dotnet/roslyn/issues/18348"
)]
public
void
IncorrectUnusedUsingWhenAttributeOnParameter_01
()
{
var
source1
=
@"using System.Runtime.InteropServices;
partial class Program
{
partial void M([Out] [In] ref int x) { }
}"
;
var
source2
=
@"partial class Program
{
partial void M(ref int x);
}"
;
var
comp
=
CreateStandardCompilation
(
new
[]
{
source1
,
source2
});
var
tree
=
comp
.
SyntaxTrees
[
0
];
//comp.VerifyDiagnostics(); // doing this first hides the symptoms of the bug
var
model
=
comp
.
GetSemanticModel
(
tree
);
// There should be no diagnostics.
model
.
GetDiagnostics
().
Verify
(
//// (1,1): hidden CS8019: Unnecessary using directive.
//// using System.Runtime.InteropServices;
//Diagnostic(ErrorCode.HDN_UnusedUsingDirective, "using System.Runtime.InteropServices;").WithLocation(1, 1)
);
}
[
Fact
,
WorkItem
(
18348
,
"https://github.com/dotnet/roslyn/issues/18348"
)]
public
void
IncorrectUnusedUsingWhenAttributeOnParameter_02
()
{
var
source1
=
@"using System.Runtime.InteropServices;
partial class Program
{
partial void M([Out] [In] ref int x);
}"
;
var
source2
=
@"partial class Program
{
partial void M(ref int x) { }
}"
;
var
comp
=
CreateStandardCompilation
(
new
[]
{
source1
,
source2
});
var
tree
=
comp
.
SyntaxTrees
[
0
];
//comp.VerifyDiagnostics(); // doing this first hides the symptoms of the bug
var
model
=
comp
.
GetSemanticModel
(
tree
);
// There should be no diagnostics.
model
.
GetDiagnostics
().
Verify
(
//// (1,1): hidden CS8019: Unnecessary using directive.
//// using System.Runtime.InteropServices;
//Diagnostic(ErrorCode.HDN_UnusedUsingDirective, "using System.Runtime.InteropServices;").WithLocation(1, 1)
);
}
}
}
src/Compilers/VisualBasic/Test/Semantic/Semantics/GetUnusedImportDirectivesTests.vb
浏览文件 @
f6b9c6eb
...
...
@@ -314,5 +314,57 @@ Imports System
~~~~~~~~~~~~~~
</
errors
>
,
suppressInfos
:
=
False
)
End
Sub
<
Fact
,
WorkItem
(
18348
,
"https://github.com/dotnet/roslyn/issues/18348"
)
>
Public
Sub
IncorrectUnusedUsingWhenAttributeOnParameter_01
()
Dim
source
=
<
compilation
>
<
file
name
=
"a.vb"
><
!
[
CDATA
[
Imports
System.Runtime.InteropServices
Partial
Class
Program
Private
Sub
M
(
<
Out
>
<
InAttribute
>
ByRef
x
As
Integer
)
End
Sub
End
Class
]]
></
file
>
<
file
name
=
"b.vb"
><
!
[
CDATA
[
Partial
Class
Program
Partial
Private
Sub
M
(
ByRef
x
As
Integer
)
End
Sub
End
Class
]]
></
file
>
</
compilation
>
Dim
comp
=
CreateCompilationWithMscorlib
(
source
)
Dim
tree
=
comp
.
SyntaxTrees
(
0
)
Dim
model
=
comp
.
GetSemanticModel
(
tree
)
Dim
diagnostics
=
model
.
GetDiagnostics
()
AssertTheseDiagnostics
(
diagnostics
,
<
errors
></
errors
>
)
End
Sub
<
Fact
,
WorkItem
(
18348
,
"https://github.com/dotnet/roslyn/issues/18348"
)
>
Public
Sub
IncorrectUnusedUsingWhenAttributeOnParameter_02
()
Dim
source
=
<
compilation
>
<
file
name
=
"a.vb"
><
!
[
CDATA
[
Imports
System.Runtime.InteropServices
Partial
Class
Program
Partial
Private
Sub
M
(
<
Out
>
<
InAttribute
>
ByRef
x
As
Integer
)
End
Sub
End
Class
]]
></
file
>
<
file
name
=
"b.vb"
><
!
[
CDATA
[
Partial
Class
Program
Private
Sub
M
(
ByRef
x
As
Integer
)
End
Sub
End
Class
]]
></
file
>
</
compilation
>
Dim
comp
=
CreateCompilationWithMscorlib
(
source
)
Dim
tree
=
comp
.
SyntaxTrees
(
0
)
Dim
model
=
comp
.
GetSemanticModel
(
tree
)
Dim
diagnostics
=
model
.
GetDiagnostics
()
AssertTheseDiagnostics
(
diagnostics
,
<
errors
></
errors
>
)
End
Sub
End
Class
End
Namespace
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录