Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
d9569c8c
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,发现更多精彩内容 >>
提交
d9569c8c
编写于
12月 22, 2014
作者:
J
jaredpar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Responding to CR feedback (changeset 1390324)
上级
3dd6ae9d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
39 addition
and
8 deletion
+39
-8
Src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
Src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
+7
-7
Src/Compilers/CSharp/Test/Semantic/Semantics/NullableConversionTests.cs
...CSharp/Test/Semantic/Semantics/NullableConversionTests.cs
+17
-1
Src/Compilers/CSharp/Test/Symbol/Compilation/SemanticModelAPITests.cs
...s/CSharp/Test/Symbol/Compilation/SemanticModelAPITests.cs
+15
-0
未找到文件。
Src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
浏览文件 @
d9569c8c
...
...
@@ -1527,10 +1527,10 @@ private BoundExpression BindCast(CastExpressionSyntax node, DiagnosticBag diagno
return
BindExplicitNullableCastFromNonNullable
(
node
,
operand
,
targetType
,
diagnostics
);
}
return
BindCastCore
(
node
,
operand
,
targetType
,
diagnostics
);
return
BindCastCore
(
node
,
operand
,
targetType
,
wasCompilerGenerated
:
operand
.
WasCompilerGenerated
,
diagnostics
:
diagnostics
);
}
private
BoundExpression
BindCastCore
(
ExpressionSyntax
node
,
BoundExpression
operand
,
TypeSymbol
targetType
,
DiagnosticBag
diagnostics
)
private
BoundExpression
BindCastCore
(
ExpressionSyntax
node
,
BoundExpression
operand
,
TypeSymbol
targetType
,
bool
wasCompilerGenerated
,
DiagnosticBag
diagnostics
)
{
HashSet
<
DiagnosticInfo
>
useSiteDiagnostics
=
null
;
Conversion
conversion
=
this
.
Conversions
.
ClassifyConversionForCast
(
operand
,
targetType
,
ref
useSiteDiagnostics
);
...
...
@@ -1601,7 +1601,7 @@ private BoundExpression BindCastCore(ExpressionSyntax node, BoundExpression oper
hasErrors
:
true
);
}
return
CreateConversion
(
node
,
operand
,
conversion
,
isCast
:
true
,
destination
:
targetType
,
diagnostics
:
diagnostics
);
return
CreateConversion
(
node
,
operand
,
conversion
,
isCast
:
true
,
wasCompilerGenerated
:
wasCompilerGenerated
,
destination
:
targetType
,
diagnostics
:
diagnostics
);
}
/// <summary>
...
...
@@ -1625,13 +1625,13 @@ private BoundExpression BindExplicitNullableCastFromNonNullable(ExpressionSyntax
var
underlyingConversion
=
Conversions
.
ClassifyConversion
(
operand
.
Type
,
underlyingTargetType
,
ref
unused
,
builtinOnly
:
true
);
if
(!
underlyingConversion
.
Exists
)
{
return
BindCastCore
(
node
,
operand
,
targetType
,
diagnostics
);
return
BindCastCore
(
node
,
operand
,
targetType
,
wasCompilerGenerated
:
operand
.
WasCompilerGenerated
,
diagnostics
:
diagnostics
);
}
var
bag
=
DiagnosticBag
.
GetInstance
();
try
{
var
underlyingExpr
=
BindCastCore
(
node
,
operand
,
targetType
.
GetNullableUnderlyingType
(),
bag
);
var
underlyingExpr
=
BindCastCore
(
node
,
operand
,
targetType
.
GetNullableUnderlyingType
(),
wasCompilerGenerated
:
false
,
diagnostics
:
bag
);
if
(
underlyingExpr
.
HasErrors
||
bag
.
HasAnyErrors
())
{
Error
(
diagnostics
,
ErrorCode
.
ERR_NoExplicitConv
,
node
,
operand
.
Type
,
targetType
);
...
...
@@ -1653,10 +1653,10 @@ private BoundExpression BindExplicitNullableCastFromNonNullable(ExpressionSyntax
if
(
underlyingExpr
.
ConstantValue
!=
null
)
{
underlyingExpr
.
WasCompilerGenerated
=
true
;
return
BindCastCore
(
node
,
underlyingExpr
,
targetType
,
diagnostics
);
return
BindCastCore
(
node
,
underlyingExpr
,
targetType
,
wasCompilerGenerated
:
operand
.
WasCompilerGenerated
,
diagnostics
:
diagnostics
);
}
return
BindCastCore
(
node
,
operand
,
targetType
,
diagnostics
);
return
BindCastCore
(
node
,
operand
,
targetType
,
wasCompilerGenerated
:
operand
.
WasCompilerGenerated
,
diagnostics
:
diagnostics
);
}
finally
{
...
...
Src/Compilers/CSharp/Test/Semantic/Semantics/NullableConversionTests.cs
浏览文件 @
d9569c8c
// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using
System.Collections.Generic
;
using
System.Linq
;
using
Microsoft.CodeAnalysis.CSharp.Symbols
;
using
Microsoft.CodeAnalysis.CSharp.Syntax
;
...
...
@@ -7,7 +8,6 @@
using
Microsoft.CodeAnalysis.Text
;
using
Roslyn.Test.Utilities
;
using
Xunit
;
using
System.Collections.Generic
;
namespace
Microsoft.CodeAnalysis.CSharp.UnitTests
{
...
...
@@ -693,6 +693,22 @@ void Test()
i = (int?)float.PositiveInfinity;
Use(i);
unchecked {
// double checks
i = (int?)3.5d;
i = (int?)double.MaxValue;
i = (int?)double.NaN;
i = (int?)double.NegativeInfinity;
i = (int?)double.PositiveInfinity;
// float checks
i = (int?)3.5d;
i = (int?)float.MaxValue;
i = (int?)float.NaN;
i = (int?)float.NegativeInfinity;
i = (int?)float.PositiveInfinity;
}
}
}
"
;
...
...
Src/Compilers/CSharp/Test/Symbol/Compilation/SemanticModelAPITests.cs
浏览文件 @
d9569c8c
...
...
@@ -3221,6 +3221,8 @@ static void Main()
Console.WriteLine(case1);
int? case2 = (int?)5.5;
Console.WriteLine(case2);
int? case3 = (int?)5;
Console.WriteLine(case3);
}
}
"
;
...
...
@@ -3232,17 +3234,30 @@ static void Main()
var
method
=
tree
.
GetRoot
().
DescendantNodes
().
OfType
<
MethodDeclarationSyntax
>().
Single
();
var
init0
=
method
.
Body
.
Statements
[
0
].
DescendantNodes
().
OfType
<
VariableDeclaratorSyntax
>().
Single
().
Initializer
.
Value
;
var
value0
=
model
.
GetConstantValue
(
init0
);
var
typeInfo0
=
model
.
GetTypeInfo
(
init0
);
Assert
.
True
(
value0
.
HasValue
);
Assert
.
Equal
(-
1
,
(
short
)
value0
.
Value
);
Assert
.
True
(
typeInfo0
.
Type
!=
null
&&
typeInfo0
.
Type
.
SpecialType
==
SpecialType
.
System_Int16
);
// The CodePlex bug indicates this should return a constant value of 5. While 'case2' should
// have that value it is not constant because of the nullable cast
var
init1
=
method
.
Body
.
Statements
[
2
].
DescendantNodes
().
OfType
<
VariableDeclaratorSyntax
>().
Single
().
Initializer
.
Value
;
var
value1
=
model
.
GetConstantValue
(
init1
);
var
typeInfo1
=
model
.
GetTypeInfo
(
init1
);
var
type1
=
comp
.
GetSpecialType
(
SpecialType
.
System_Nullable_T
).
Construct
(
comp
.
GetSpecialType
(
SpecialType
.
System_Int32
));
Assert
.
False
(
value1
.
HasValue
);
Assert
.
True
(
typeInfo1
.
Type
!=
null
&&
typeInfo1
.
Type
.
Equals
(
type1
));
var
init2
=
method
.
Body
.
Statements
[
4
].
DescendantNodes
().
OfType
<
VariableDeclaratorSyntax
>().
Single
().
Initializer
.
Value
;
var
value2
=
model
.
GetConstantValue
(
init2
);
var
typeInfo2
=
model
.
GetTypeInfo
(
init2
);
var
type2
=
comp
.
GetSpecialType
(
SpecialType
.
System_Nullable_T
).
Construct
(
comp
.
GetSpecialType
(
SpecialType
.
System_Int32
));
Assert
.
False
(
value2
.
HasValue
);
Assert
.
True
(
typeInfo2
.
Type
!=
null
&&
typeInfo2
.
Type
.
Equals
(
type2
));
var
output
=
@"
-1
5
5"
;
CompileAndVerify
(
compilation
:
comp
,
expectedOutput
:
output
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录