Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
2030b159
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,发现更多精彩内容 >>
提交
2030b159
编写于
8月 03, 2015
作者:
A
AlekseyTs
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Properly adjust result type of a user-defined conversion for lifted case.
Fixes #4132.
上级
7c1dd49d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
124 addition
and
1 deletion
+124
-1
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Conversion.cs
...rtable/Lowering/LocalRewriter/LocalRewriter_Conversion.cs
+13
-1
src/Compilers/CSharp/Test/Semantic/Semantics/OperatorTests.cs
...Compilers/CSharp/Test/Semantic/Semantics/OperatorTests.cs
+52
-0
src/Compilers/VisualBasic/Test/Semantic/Semantics/CompoundAssignment.vb
...VisualBasic/Test/Semantic/Semantics/CompoundAssignment.vb
+59
-0
未找到文件。
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Conversion.cs
浏览文件 @
2030b159
...
...
@@ -554,11 +554,23 @@ private BoundExpression MakeImplicitConversion(BoundExpression rewrittenOperand,
@checked
);
}
TypeSymbol
userDefinedConversionRewrittenType
=
conversion
.
Method
.
ReturnType
;
if
(
rewrittenOperand
.
Type
!=
conversion
.
Method
.
ParameterTypes
[
0
])
{
Debug
.
Assert
(
rewrittenOperand
.
Type
.
IsNullableType
());
Debug
.
Assert
(
rewrittenOperand
.
Type
.
GetNullableUnderlyingType
()
==
conversion
.
Method
.
ParameterTypes
[
0
]);
Debug
.
Assert
(!
userDefinedConversionRewrittenType
.
IsNullableType
());
// Lifted conversion, wrap return type in Nullable
userDefinedConversionRewrittenType
=
((
NamedTypeSymbol
)
rewrittenOperand
.
Type
.
OriginalDefinition
).
Construct
(
userDefinedConversionRewrittenType
);
}
BoundExpression
userDefined
=
RewriteUserDefinedConversion
(
syntax
,
rewrittenOperand
,
conversion
.
Method
,
conversion
.
Method
.
Retur
nType
,
userDefinedConversionRewritte
nType
,
conversion
.
Kind
);
if
(
userDefined
.
Type
!=
conversion
.
BestUserDefinedConversionAnalysis
.
ToType
)
...
...
src/Compilers/CSharp/Test/Semantic/Semantics/OperatorTests.cs
浏览文件 @
2030b159
...
...
@@ -8676,5 +8676,57 @@ public static void Main (string[] args)
System.Int32
"
);
}
[
Fact
,
WorkItem
(
4132
,
"https://github.com/dotnet/roslyn/issues/4132"
)]
public
void
Issue4132
()
{
string
source
=
@"
using System;
namespace NullableMathRepro
{
class Program
{
static void Main(string[] args)
{
int? x = 0;
x += 5;
Console.WriteLine(""'x' is {0}"", x);
IntHolder? y = 0;
y += 5;
Console.WriteLine(""'y' is {0}"", y);
}
}
struct IntHolder
{
private int x;
public static implicit operator int (IntHolder ih)
{
Console.WriteLine(""operator int (IntHolder ih)"");
return ih.x;
}
public static implicit operator IntHolder(int i)
{
Console.WriteLine(""operator IntHolder(int i)"");
return new IntHolder { x = i };
}
public override string ToString()
{
return x.ToString();
}
}
}"
;
CompileAndVerify
(
source
:
source
,
expectedOutput
:
@"'x' is 5
operator IntHolder(int i)
operator int (IntHolder ih)
operator IntHolder(int i)
'y' is 5"
);
}
}
}
src/Compilers/VisualBasic/Test/Semantic/Semantics/CompoundAssignment.vb
浏览文件 @
2030b159
...
...
@@ -2701,9 +2701,68 @@ Position get for item 'Foo'
Position
set
for
item
'Foo'
False
False
]]
>
)
End
Sub
<
Fact
,
WorkItem
(
4132
,
"https://github.com/dotnet/roslyn/issues/4132"
)
>
Public
Sub
Issue4132
()
Dim
compilationDef
=
<
compilation
>
<
file
name
=
"a.vb"
>
Imports
System
Namespace
NullableMathRepro
Module
Program
Sub
Main
()
Dim
x
As
Integer
?
=
0
x
+=
5
Console
.
WriteLine
(
"'x' is {0}"
,
x
)
Dim
y
As
IntHolder
?
=
0
y
+=
5
Console
.
WriteLine
(
"'y' is {0}"
,
y
)
End
Sub
End
Module
Structure
IntHolder
Private
x
As
Integer
Public
Shared
Widening
Operator
CType
(
ih
As
IntHolder
)
As
Integer
Console
.
WriteLine
(
"operator int (IntHolder ih)"
)
Return
ih
.
x
End
Operator
Public
Shared
Widening
Operator
CType
(
i
As
Integer
)
As
IntHolder
Console
.
WriteLine
(
"operator IntHolder(int i)"
)
Return
New
IntHolder
With
{.
x
=
i
}
End
Operator
Public
Shared
Operator
+
(
x
As
IntHolder
,
y
As
Integer
)
As
Integer
Return
CInt
(
x
)
+
y
End
Operator
Public
Overrides
Function
ToString
()
As
String
Return
x
.
ToString
()
End
Function
End
Structure
End
Namespace
</
file
>
</
compilation
>
Dim
compilation
=
CompilationUtils
.
CreateCompilationWithMscorlibAndVBRuntime
(
compilationDef
,
TestOptions
.
ReleaseExe
)
CompileAndVerify
(
compilation
,
<
!
[
CDATA
[
'x' is 5
operator
IntHolder
(
int
i
)
operator
int
(
IntHolder
ih
)
operator
IntHolder
(
int
i
)
'y' is 5
]]
>
)
End
Sub
End
Class
End
Namespace
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录