Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
fc46138e
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,发现更多精彩内容 >>
提交
fc46138e
编写于
6月 22, 2017
作者:
O
Omar Tawfik
提交者:
vsadov
6月 26, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Produce error at callsite as well.
上级
0bdeaf34
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
236 addition
and
5 deletion
+236
-5
src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs
src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs
+6
-0
src/Compilers/CSharp/Test/Semantic/Semantics/RefExtensionMethodsTests.cs
...Sharp/Test/Semantic/Semantics/RefExtensionMethodsTests.cs
+227
-2
src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs
...ers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs
+3
-3
未找到文件。
src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs
浏览文件 @
fc46138e
...
...
@@ -923,6 +923,12 @@ private static void CheckRestrictedTypeReceiver(BoundExpression expression, Comp
// If this was a ref extension method, receiverArgument must be checked for L-value constraints.
// This helper method will also replace it with a BoundBadExpression if it was invalid.
receiverArgument
=
CheckValue
(
receiverArgument
,
BindValueKind
.
RefOrOut
,
diagnostics
);
CheckFeatureAvailability
(
receiverArgument
.
Syntax
,
MessageID
.
IDS_FeatureRefExtensionMethods
,
diagnostics
);
}
else
if
(
receiverParameter
.
RefKind
==
RefKind
.
RefReadOnly
)
{
CheckFeatureAvailability
(
receiverArgument
.
Syntax
,
MessageID
.
IDS_FeatureRefExtensionMethods
,
diagnostics
);
}
ArrayBuilder
<
BoundExpression
>
builder
=
ArrayBuilder
<
BoundExpression
>.
GetInstance
(
analyzedArguments
.
Arguments
.
Count
);
...
...
src/Compilers/CSharp/Test/Semantic/Semantics/RefExtensionMethodsTests.cs
浏览文件 @
fc46138e
...
...
@@ -1928,7 +1928,7 @@ public void ParameterSymbolsRetrievedThroughSemanticModel_RefExtensionMethods()
var
code
=
@"
public static class Ext
{
public static void Method(ref int p) { }
public static void Method(ref
this
int p) { }
}"
;
var
comp
=
CreateCompilationWithMscorlibAndSystemCore
(
code
).
VerifyDiagnostics
();
...
...
@@ -1947,7 +1947,7 @@ public void ParameterSymbolsRetrievedThroughSemanticModel_RefReadOnlyExtensionMe
var
code
=
@"
public static class Ext
{
public static void Method(ref readonly int p) { }
public static void Method(ref readonly
this
int p) { }
}"
;
var
comp
=
CreateCompilationWithMscorlibAndSystemCore
(
code
).
VerifyDiagnostics
();
...
...
@@ -1960,6 +1960,231 @@ public static class Ext
Assert
.
Equal
(
RefKind
.
RefReadOnly
,
symbol
.
RefKind
);
}
[
Fact
]
public
void
UsingRefExtensionMethodsBeforeVersion7_2ProducesDiagnostics_RefSyntax_SameCompilation
()
{
var
code
=
@"
public static class Ext
{
public static void Print(ref this int p)
{
System.Console.WriteLine(p);
}
}
public static class Program
{
public static void Main()
{
int p = 5;
p.Print();
}
}"
;
CreateCompilationWithMscorlibAndSystemCore
(
code
,
parseOptions
:
CSharpParseOptions
.
Default
.
WithLanguageVersion
(
LanguageVersion
.
CSharp7_1
)).
VerifyDiagnostics
(
// (4,34): error CS8302: Feature 'reference extension methods' is not available in C# 7.1. Please use language version 7.2 or greater.
// public static void Print(ref this int p)
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion7_1
,
"this"
).
WithArguments
(
"reference extension methods"
,
"7.2"
).
WithLocation
(
4
,
34
),
// (14,9): error CS8302: Feature 'reference extension methods' is not available in C# 7.1. Please use language version 7.2 or greater.
// p.Print();
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion7_1
,
"p"
).
WithArguments
(
"reference extension methods"
,
"7.2"
).
WithLocation
(
14
,
9
));
CompileAndVerify
(
code
,
additionalRefs
:
new
[]
{
SystemCoreRef
},
expectedOutput
:
"5"
);
}
[
Fact
]
public
void
UsingRefExtensionMethodsBeforeVersion7_2ProducesDiagnostics_RefSyntax_DifferentCompilation
()
{
var
reference
=
CreateCompilationWithMscorlibAndSystemCore
(
@"
public static class Ext
{
public static void Print(ref this int p)
{
System.Console.WriteLine(p);
}
}"
);
var
code
=
@"
public static class Program
{
public static void Main()
{
int p = 5;
p.Print();
}
}"
;
CreateCompilationWithMscorlibAndSystemCore
(
text
:
code
,
parseOptions
:
CSharpParseOptions
.
Default
.
WithLanguageVersion
(
LanguageVersion
.
CSharp7_1
),
references
:
new
[]
{
reference
.
ToMetadataReference
()
}).
VerifyDiagnostics
(
// (7,9): error CS8302: Feature 'reference extension methods' is not available in C# 7.1. Please use language version 7.2 or greater.
// p.Print();
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion7_1
,
"p"
).
WithArguments
(
"reference extension methods"
,
"7.2"
).
WithLocation
(
7
,
9
));
CreateCompilationWithMscorlibAndSystemCore
(
text
:
code
,
parseOptions
:
CSharpParseOptions
.
Default
.
WithLanguageVersion
(
LanguageVersion
.
CSharp7_1
),
references
:
new
[]
{
reference
.
EmitToImageReference
()
}).
VerifyDiagnostics
(
// (7,9): error CS8302: Feature 'reference extension methods' is not available in C# 7.1. Please use language version 7.2 or greater.
// p.Print();
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion7_1
,
"p"
).
WithArguments
(
"reference extension methods"
,
"7.2"
).
WithLocation
(
7
,
9
));
CompileAndVerify
(
code
,
additionalRefs
:
new
[]
{
SystemCoreRef
,
reference
.
ToMetadataReference
()
},
expectedOutput
:
"5"
);
CompileAndVerify
(
code
,
additionalRefs
:
new
[]
{
SystemCoreRef
,
reference
.
EmitToImageReference
()
},
expectedOutput
:
"5"
);
}
[
Fact
]
public
void
UsingRefExtensionMethodsBeforeVersion7_2ProducesDiagnostics_RefReadOnlySyntax_SameCompilation
()
{
var
code
=
@"
public static class Ext
{
public static void Print(ref readonly this int p)
{
System.Console.WriteLine(p);
}
}
public static class Program
{
public static void Main()
{
int p = 5;
p.Print();
}
}"
;
CreateCompilationWithMscorlibAndSystemCore
(
code
,
parseOptions
:
CSharpParseOptions
.
Default
.
WithLanguageVersion
(
LanguageVersion
.
CSharp7_1
)).
VerifyDiagnostics
(
// (4,34): error CS8302: Feature 'readonly references' is not available in C# 7.1. Please use language version 7.2 or greater.
// public static void Print(ref readonly this int p)
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion7_1
,
"readonly"
).
WithArguments
(
"readonly references"
,
"7.2"
).
WithLocation
(
4
,
34
),
// (4,43): error CS8302: Feature 'reference extension methods' is not available in C# 7.1. Please use language version 7.2 or greater.
// public static void Print(ref readonly this int p)
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion7_1
,
"this"
).
WithArguments
(
"reference extension methods"
,
"7.2"
).
WithLocation
(
4
,
43
),
// (14,9): error CS8302: Feature 'reference extension methods' is not available in C# 7.1. Please use language version 7.2 or greater.
// p.Print();
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion7_1
,
"p"
).
WithArguments
(
"reference extension methods"
,
"7.2"
).
WithLocation
(
14
,
9
));
CompileAndVerify
(
code
,
additionalRefs
:
new
[]
{
SystemCoreRef
},
expectedOutput
:
"5"
);
}
[
Fact
]
public
void
UsingRefExtensionMethodsBeforeVersion7_2ProducesDiagnostics_RefReadOnlySyntax_DifferentCompilation
()
{
var
reference
=
CreateCompilationWithMscorlibAndSystemCore
(
@"
public static class Ext
{
public static void Print(ref readonly this int p)
{
System.Console.WriteLine(p);
}
}"
);
var
code
=
@"
public static class Program
{
public static void Main()
{
int p = 5;
p.Print();
}
}"
;
CreateCompilationWithMscorlibAndSystemCore
(
text
:
code
,
parseOptions
:
CSharpParseOptions
.
Default
.
WithLanguageVersion
(
LanguageVersion
.
CSharp7_1
),
references
:
new
[]
{
reference
.
ToMetadataReference
()
}).
VerifyDiagnostics
(
// (7,9): error CS8302: Feature 'reference extension methods' is not available in C# 7.1. Please use language version 7.2 or greater.
// p.Print();
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion7_1
,
"p"
).
WithArguments
(
"reference extension methods"
,
"7.2"
).
WithLocation
(
7
,
9
));
CreateCompilationWithMscorlibAndSystemCore
(
text
:
code
,
parseOptions
:
CSharpParseOptions
.
Default
.
WithLanguageVersion
(
LanguageVersion
.
CSharp7_1
),
references
:
new
[]
{
reference
.
EmitToImageReference
()
}).
VerifyDiagnostics
(
// (7,9): error CS8302: Feature 'reference extension methods' is not available in C# 7.1. Please use language version 7.2 or greater.
// p.Print();
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion7_1
,
"p"
).
WithArguments
(
"reference extension methods"
,
"7.2"
).
WithLocation
(
7
,
9
));
CompileAndVerify
(
code
,
additionalRefs
:
new
[]
{
SystemCoreRef
,
reference
.
ToMetadataReference
()
},
expectedOutput
:
"5"
);
CompileAndVerify
(
code
,
additionalRefs
:
new
[]
{
SystemCoreRef
,
reference
.
EmitToImageReference
()
},
expectedOutput
:
"5"
);
}
[
Fact
]
public
void
UsingRefExtensionMethodsBeforeVersion7_2ProducesDiagnostics_InSyntax_SameCompilation
()
{
var
code
=
@"
public static class Ext
{
public static void Print(in this int p)
{
System.Console.WriteLine(p);
}
}
public static class Program
{
public static void Main()
{
int p = 5;
p.Print();
}
}"
;
CreateCompilationWithMscorlibAndSystemCore
(
code
,
parseOptions
:
CSharpParseOptions
.
Default
.
WithLanguageVersion
(
LanguageVersion
.
CSharp7_1
)).
VerifyDiagnostics
(
// (4,30): error CS8302: Feature 'readonly references' is not available in C# 7.1. Please use language version 7.2 or greater.
// public static void Print(in this int p)
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion7_1
,
"in"
).
WithArguments
(
"readonly references"
,
"7.2"
).
WithLocation
(
4
,
30
),
// (4,33): error CS8302: Feature 'reference extension methods' is not available in C# 7.1. Please use language version 7.2 or greater.
// public static void Print(in this int p)
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion7_1
,
"this"
).
WithArguments
(
"reference extension methods"
,
"7.2"
).
WithLocation
(
4
,
33
),
// (14,9): error CS8302: Feature 'reference extension methods' is not available in C# 7.1. Please use language version 7.2 or greater.
// p.Print();
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion7_1
,
"p"
).
WithArguments
(
"reference extension methods"
,
"7.2"
).
WithLocation
(
14
,
9
));
CompileAndVerify
(
code
,
additionalRefs
:
new
[]
{
SystemCoreRef
},
expectedOutput
:
"5"
);
}
[
Fact
]
public
void
UsingRefExtensionMethodsBeforeVersion7_2ProducesDiagnostics_InSyntax_DifferentCompilation
()
{
var
reference
=
CreateCompilationWithMscorlibAndSystemCore
(
@"
public static class Ext
{
public static void Print(in this int p)
{
System.Console.WriteLine(p);
}
}"
);
var
code
=
@"
public static class Program
{
public static void Main()
{
int p = 5;
p.Print();
}
}"
;
CreateCompilationWithMscorlibAndSystemCore
(
text
:
code
,
parseOptions
:
CSharpParseOptions
.
Default
.
WithLanguageVersion
(
LanguageVersion
.
CSharp7_1
),
references
:
new
[]
{
reference
.
ToMetadataReference
()
}).
VerifyDiagnostics
(
// (7,9): error CS8302: Feature 'reference extension methods' is not available in C# 7.1. Please use language version 7.2 or greater.
// p.Print();
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion7_1
,
"p"
).
WithArguments
(
"reference extension methods"
,
"7.2"
).
WithLocation
(
7
,
9
));
CreateCompilationWithMscorlibAndSystemCore
(
text
:
code
,
parseOptions
:
CSharpParseOptions
.
Default
.
WithLanguageVersion
(
LanguageVersion
.
CSharp7_1
),
references
:
new
[]
{
reference
.
EmitToImageReference
()
}).
VerifyDiagnostics
(
// (7,9): error CS8302: Feature 'reference extension methods' is not available in C# 7.1. Please use language version 7.2 or greater.
// p.Print();
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion7_1
,
"p"
).
WithArguments
(
"reference extension methods"
,
"7.2"
).
WithLocation
(
7
,
9
));
CompileAndVerify
(
code
,
additionalRefs
:
new
[]
{
SystemCoreRef
,
reference
.
ToMetadataReference
()
},
expectedOutput
:
"5"
);
CompileAndVerify
(
code
,
additionalRefs
:
new
[]
{
SystemCoreRef
,
reference
.
EmitToImageReference
()
},
expectedOutput
:
"5"
);
}
private
const
string
ExtraRefReadOnlyIL
=
@"
.class private auto ansi sealed beforefieldinit Microsoft.CodeAnalysis.EmbeddedAttribute extends [mscorlib]System.Attribute
{
...
...
src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs
浏览文件 @
fc46138e
...
...
@@ -5614,7 +5614,7 @@ public static void Main()
}
}"
;
CreateCompilationWithMscorlibAndSystemCore
(
code
,
parseOptions
:
CSharpParseOptions
.
Default
.
WithLanguageVersion
(
LanguageVersion
.
CSharp7_1
)).
VerifyDiagnostics
(
CreateCompilationWithMscorlibAndSystemCore
(
code
,
parseOptions
:
CSharpParseOptions
.
Default
.
WithLanguageVersion
(
LanguageVersion
.
CSharp7_1
)).
GetParseDiagnostics
().
Verify
(
// (4,34): error CS8302: Feature 'readonly references' is not available in C# 7.1. Please use language version 7.2 or greater.
// public static void Print(ref readonly this int p)
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion7_1
,
"readonly"
).
WithArguments
(
"readonly references"
,
"7.2"
).
WithLocation
(
4
,
34
),
...
...
@@ -5645,7 +5645,7 @@ public static void Main()
}
}"
;
CreateCompilationWithMscorlibAndSystemCore
(
code
,
parseOptions
:
CSharpParseOptions
.
Default
.
WithLanguageVersion
(
LanguageVersion
.
CSharp7_1
)).
VerifyDiagnostics
(
CreateCompilationWithMscorlibAndSystemCore
(
code
,
parseOptions
:
CSharpParseOptions
.
Default
.
WithLanguageVersion
(
LanguageVersion
.
CSharp7_1
)).
GetParseDiagnostics
().
Verify
(
// (4,30): error CS8302: Feature 'readonly references' is not available in C# 7.1. Please use language version 7.2 or greater.
// public static void Print(in this int p)
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion7_1
,
"in"
).
WithArguments
(
"readonly references"
,
"7.2"
).
WithLocation
(
4
,
30
),
...
...
@@ -5676,7 +5676,7 @@ public static void Main()
}
}"
;
CreateCompilationWithMscorlibAndSystemCore
(
code
,
parseOptions
:
CSharpParseOptions
.
Default
.
WithLanguageVersion
(
LanguageVersion
.
CSharp7_1
)).
VerifyDiagnostics
(
CreateCompilationWithMscorlibAndSystemCore
(
code
,
parseOptions
:
CSharpParseOptions
.
Default
.
WithLanguageVersion
(
LanguageVersion
.
CSharp7_1
)).
GetParseDiagnostics
().
Verify
(
// (4,34): error CS8302: Feature 'reference extension methods' is not available in C# 7.1. Please use language version 7.2 or greater.
// public static void Print(ref this int p)
Diagnostic
(
ErrorCode
.
ERR_FeatureNotAvailableInVersion7_1
,
"this"
).
WithArguments
(
"reference extension methods"
,
"7.2"
).
WithLocation
(
4
,
34
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录