Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
14fd4d43
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,发现更多精彩内容 >>
提交
14fd4d43
编写于
4月 14, 2015
作者:
A
AlekseyTs
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Do not report CS1720 warning when member being accessed is a static member.
Fixes issue #1845.
上级
12bdab4c
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
60 addition
and
16 deletion
+60
-16
src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
+25
-9
src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs
src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs
+9
-0
src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs
...lers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs
+26
-7
未找到文件。
src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
浏览文件 @
14fd4d43
...
...
@@ -4487,11 +4487,6 @@ private bool IsUsingAliasInScope(string name)
return
BadExpression
(
node
,
boundLeft
);
}
if
(
boundLeft
.
Kind
==
BoundKind
.
DefaultOperator
&&
boundLeft
.
ConstantValue
==
ConstantValue
.
Null
)
{
Error
(
diagnostics
,
ErrorCode
.
WRN_DotOnDefault
,
node
,
leftType
);
}
var
lookupResult
=
LookupResult
.
GetInstance
();
try
{
...
...
@@ -4649,6 +4644,14 @@ private bool IsUsingAliasInScope(string name)
}
}
private
static
void
WarnOnAccessOfOffDefault
(
CSharpSyntaxNode
node
,
BoundExpression
boundLeft
,
DiagnosticBag
diagnostics
)
{
if
(
boundLeft
!=
null
&&
boundLeft
.
Kind
==
BoundKind
.
DefaultOperator
&&
boundLeft
.
ConstantValue
==
ConstantValue
.
Null
)
{
Error
(
diagnostics
,
ErrorCode
.
WRN_DotOnDefault
,
node
,
boundLeft
.
Type
);
}
}
/// <summary>
/// Create a value from the expression that can be used as a left-hand-side
/// of a member access. This method special-cases method and property
...
...
@@ -5256,6 +5259,11 @@ private static void CombineExtensionMethodArguments(BoundExpression receiver, An
}
}
if
(!
fieldSymbol
.
IsStatic
)
{
WarnOnAccessOfOffDefault
(
node
,
receiver
,
diagnostics
);
}
TypeSymbol
fieldType
=
fieldSymbol
.
GetFieldType
(
this
.
FieldsBeingBound
);
BoundExpression
expr
=
new
BoundFieldAccess
(
node
,
receiver
,
fieldSymbol
,
constantValueOpt
,
resultKind
,
fieldType
,
hasErrors
:
(
hasErrors
||
hasError
));
...
...
@@ -5320,6 +5328,11 @@ private bool InEnumMemberInitializer()
{
bool
hasError
=
this
.
CheckInstanceOrStatic
(
node
,
receiver
,
propertySymbol
,
ref
lookupResult
,
diagnostics
);
if
(!
propertySymbol
.
IsStatic
)
{
WarnOnAccessOfOffDefault
(
node
,
receiver
,
diagnostics
);
}
return
new
BoundPropertyAccess
(
node
,
receiver
,
propertySymbol
,
lookupResult
,
propertySymbol
.
Type
,
hasErrors
:
(
hasErrors
||
hasError
));
}
...
...
@@ -5337,6 +5350,11 @@ private bool InEnumMemberInitializer()
bool
hasError
=
this
.
CheckInstanceOrStatic
(
node
,
receiver
,
eventSymbol
,
ref
lookupResult
,
diagnostics
);
if
(!
eventSymbol
.
IsStatic
)
{
WarnOnAccessOfOffDefault
(
node
,
receiver
,
diagnostics
);
}
return
new
BoundEventAccess
(
node
,
receiver
,
eventSymbol
,
isUsableAsField
,
lookupResult
,
eventSymbol
.
Type
,
hasErrors
:
(
hasErrors
||
hasError
));
}
...
...
@@ -5562,10 +5580,8 @@ private BoundExpression BindElementOrIndexerAccess(ExpressionSyntax node, BoundE
{
return
BadIndexerExpression
(
node
,
expr
,
analyzedArguments
,
null
,
diagnostics
);
}
else
if
(
expr
.
Kind
==
BoundKind
.
DefaultOperator
&&
((
BoundDefaultOperator
)
expr
).
ConstantValue
==
ConstantValue
.
Null
)
{
Error
(
diagnostics
,
ErrorCode
.
WRN_DotOnDefault
,
node
,
expr
.
Type
);
}
WarnOnAccessOfOffDefault
(
node
,
expr
,
diagnostics
);
// Did we have any errors?
if
(
analyzedArguments
.
HasErrors
||
expr
.
HasAnyErrors
)
...
...
src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs
浏览文件 @
14fd4d43
...
...
@@ -849,6 +849,15 @@ private static void CheckRestrictedTypeReceiver(BoundExpression expression, Comp
gotError
=
true
;
}
if
(!
method
.
IsStatic
)
{
WarnOnAccessOfOffDefault
(
node
.
Kind
()
==
SyntaxKind
.
InvocationExpression
?
((
InvocationExpressionSyntax
)
node
).
Expression
:
node
,
receiver
,
diagnostics
);
}
return
new
BoundCall
(
node
,
receiver
,
method
,
args
,
argNames
,
argRefKinds
,
isDelegateCall
:
false
,
expanded
:
expanded
,
invokedAsExtensionMethod
:
invokedAsExtensionMethod
,
argsToParamsOpt
:
argsToParams
,
resultKind
:
LookupResultKind
.
Viable
,
type
:
returnType
,
hasErrors
:
gotError
);
...
...
src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs
浏览文件 @
14fd4d43
...
...
@@ -20816,13 +20816,7 @@ static class C
// (26,9): warning CS1720: Expression will always cause a System.NullReferenceException because the default value of 'T6' is null
Diagnostic(ErrorCode.WRN_DotOnDefault, "default(T6).GetHashCode").WithArguments("T6").WithLocation(26, 9),
// (28,9): warning CS1720: Expression will always cause a System.NullReferenceException because the default value of 'T6' is null
Diagnostic(ErrorCode.WRN_DotOnDefault, "default(T6).P").WithArguments("T6").WithLocation(28, 9),
// (31,9): warning CS1720: Expression will always cause a System.NullReferenceException because the default value of 'object' is null
Diagnostic(ErrorCode.WRN_DotOnDefault, "default(object).E").WithArguments("object").WithLocation(31, 9),
// (35,9): warning CS1720: Expression will always cause a System.NullReferenceException because the default value of 'T4' is null
Diagnostic(ErrorCode.WRN_DotOnDefault, "default(T4).E").WithArguments("T4").WithLocation(35, 9),
// (37,9): warning CS1720: Expression will always cause a System.NullReferenceException because the default value of 'T6' is null
Diagnostic(ErrorCode.WRN_DotOnDefault, "default(T6).E").WithArguments("T6").WithLocation(37, 9));
Diagnostic(ErrorCode.WRN_DotOnDefault, "default(T6).P").WithArguments("T6").WithLocation(28, 9));
}
[Fact]
...
...
@@ -20894,6 +20888,31 @@ class C
Diagnostic(ErrorCode.WRN_DotOnDefault, "default(T4)[1]").WithArguments("T4").WithLocation(38, 9));
}
[Fact]
public void CS1720WRN_DotOnDefault03()
{
var source =
@"static class A
{
static void Main()
{
System.Console.WriteLine(default(string).IsNull());
}
internal static bool IsNull(this string val)
{
return (object)val == null;
}
}
";
CompileAndVerify(source, expectedOutput: "True", additionalRefs: new[] { SystemCoreRef }).VerifyDiagnostics(
// Do not report the following warning:
// (5,34): warning CS1720: Expression will always cause a System.NullReferenceException because the default value of 'string' is null
// System.Console.WriteLine(default(string).IsNull());
// Diagnostic(ErrorCode.WRN_DotOnDefault, "default(string).IsNull").WithArguments("string").WithLocation(5, 34)
);
}
[Fact]
public void CS1723WRN_BadXMLRefTypeVar()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录