Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
393f18b6
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,发现更多精彩内容 >>
提交
393f18b6
编写于
5月 20, 2019
作者:
Y
yair halberstadt
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Distinguish between RequiresInstanceReciever and IsStatic
上级
9d7a2525
变更
25
隐藏空白更改
内联
并排
Showing
25 changed file
with
64 addition
and
51 deletion
+64
-51
src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs
src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs
+7
-7
src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs
src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs
+2
-2
src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
+3
-3
src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs
src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs
+4
-4
src/Compilers/CSharp/Portable/Binder/Semantics/AccessCheck.cs
...Compilers/CSharp/Portable/Binder/Semantics/AccessCheck.cs
+1
-1
src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/Conversions.cs
...harp/Portable/Binder/Semantics/Conversions/Conversions.cs
+1
-1
src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/OverloadResolution.cs
...Binder/Semantics/OverloadResolution/OverloadResolution.cs
+1
-1
src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/OverloadResolutionResult.cs
.../Semantics/OverloadResolution/OverloadResolutionResult.cs
+5
-3
src/Compilers/CSharp/Portable/CodeGen/EmitExpression.cs
src/Compilers/CSharp/Portable/CodeGen/EmitExpression.cs
+2
-2
src/Compilers/CSharp/Portable/CodeGen/Optimizer.cs
src/Compilers/CSharp/Portable/CodeGen/Optimizer.cs
+1
-1
src/Compilers/CSharp/Portable/FlowAnalysis/AbstractFlowPass.cs
...ompilers/CSharp/Portable/FlowAnalysis/AbstractFlowPass.cs
+3
-3
src/Compilers/CSharp/Portable/FlowAnalysis/LocalDataFlowPass.cs
...mpilers/CSharp/Portable/FlowAnalysis/LocalDataFlowPass.cs
+2
-2
src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs
src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs
+3
-3
src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker_Patterns.cs
...s/CSharp/Portable/FlowAnalysis/NullableWalker_Patterns.cs
+1
-1
src/Compilers/CSharp/Portable/Lowering/DiagnosticsPass_ExpressionTrees.cs
...harp/Portable/Lowering/DiagnosticsPass_ExpressionTrees.cs
+1
-1
src/Compilers/CSharp/Portable/Lowering/LambdaRewriter/ExpressionLambdaRewriter.cs
...table/Lowering/LambdaRewriter/ExpressionLambdaRewriter.cs
+5
-5
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Call.cs
...arp/Portable/Lowering/LocalRewriter/LocalRewriter_Call.cs
+2
-2
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Conversion.cs
...rtable/Lowering/LocalRewriter/LocalRewriter_Conversion.cs
+1
-1
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_DelegateCreationExpression.cs
...LocalRewriter/LocalRewriter_DelegateCreationExpression.cs
+1
-1
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LoweredDynamicOperationFactory.cs
.../Lowering/LocalRewriter/LoweredDynamicOperationFactory.cs
+1
-1
src/Compilers/CSharp/Portable/Lowering/SpillSequenceSpiller.cs
...ompilers/CSharp/Portable/Lowering/SpillSequenceSpiller.cs
+1
-1
src/Compilers/CSharp/Portable/Symbols/MethodSymbol.cs
src/Compilers/CSharp/Portable/Symbols/MethodSymbol.cs
+1
-1
src/Compilers/CSharp/Portable/Symbols/Source/LocalFunctionSymbol.cs
...ers/CSharp/Portable/Symbols/Source/LocalFunctionSymbol.cs
+2
-4
src/Compilers/CSharp/Portable/Symbols/Symbol.cs
src/Compilers/CSharp/Portable/Symbols/Symbol.cs
+5
-0
src/Compilers/CSharp/Portable/Symbols/Wrapped/WrappedMethodSymbol.cs
...rs/CSharp/Portable/Symbols/Wrapped/WrappedMethodSymbol.cs
+8
-0
未找到文件。
src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs
浏览文件 @
393f18b6
...
...
@@ -246,9 +246,9 @@ private BoundExpression CheckValue(BoundExpression expr, BindValueKind valueKind
// Since we have a concrete member in hand, we can resolve the receiver.
var
typeOrValue
=
(
BoundTypeOrValueExpression
)
receiver
;
receiver
=
otherSymbol
.
IsStatic
?
null
// no receiver required
:
typeOrValue
.
Data
.
ValueExpression
;
receiver
=
otherSymbol
.
RequiresInstanceReciever
?
typeOrValue
.
Data
.
ValueExpression
:
null
;
// no receiver required
}
return
new
BoundBadExpression
(
expr
.
Syntax
,
...
...
@@ -868,7 +868,7 @@ private bool CheckIsValidReceiverForVariable(SyntaxNode node, BoundExpression re
/// </remarks>
private
static
bool
RequiresVariableReceiver
(
BoundExpression
receiver
,
Symbol
symbol
)
{
return
!
symbol
.
IsStatic
return
symbol
.
RequiresInstanceReciever
&&
symbol
.
Kind
!=
SymbolKind
.
Event
&&
receiver
?.
Type
?.
IsValueType
==
true
;
}
...
...
@@ -1114,7 +1114,7 @@ bool isRefEscape
//• the safe-to-escape of all argument expressions(including the receiver)
//
if
(
symbol
.
IsStatic
)
if
(
!
symbol
.
RequiresInstanceReciever
)
{
// ignore receiver when symbol is static
receiverOpt
=
null
;
...
...
@@ -1221,7 +1221,7 @@ bool isRefEscape
// o no ref or out argument(excluding the receiver and arguments of ref-like types) may have a narrower ref-safe-to-escape than E1; and
// o no argument(including the receiver) may have a narrower safe-to-escape than E1.
if
(
symbol
.
IsStatic
)
if
(
!
symbol
.
RequiresInstanceReciever
)
{
// ignore receiver when symbol is static
receiverOpt
=
null
;
...
...
@@ -1322,7 +1322,7 @@ bool isRefEscape
uint
scopeOfTheContainingExpression
,
DiagnosticBag
diagnostics
)
{
if
(
symbol
.
IsStatic
)
if
(
!
symbol
.
RequiresInstanceReciever
)
{
// ignore receiver when symbol is static
receiverOpt
=
null
;
...
...
src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs
浏览文件 @
393f18b6
...
...
@@ -485,7 +485,7 @@ private BoundMethodGroup FixMethodGroupWithTypeOrValue(BoundMethodGroup group, C
BoundExpression
receiverOpt
=
group
.
ReceiverOpt
;
Debug
.
Assert
(
receiverOpt
!=
null
);
Debug
.
Assert
((
object
)
conversion
.
Method
!=
null
);
receiverOpt
=
ReplaceTypeOrValueReceiver
(
receiverOpt
,
conversion
.
Method
.
IsStatic
&&
!
conversion
.
IsExtensionMethod
,
diagnostics
);
receiverOpt
=
ReplaceTypeOrValueReceiver
(
receiverOpt
,
!
conversion
.
Method
.
RequiresInstanceReciever
&&
!
conversion
.
IsExtensionMethod
,
diagnostics
);
return
group
.
Update
(
group
.
TypeArgumentsOpt
,
group
.
Name
,
...
...
@@ -599,7 +599,7 @@ private bool MemberGroupFinalValidationAccessibilityChecks(BoundExpression recei
// None of the checks below apply if the receiver can't be classified as a type or value.
Debug
.
Assert
(!
invokedAsExtensionMethod
);
}
else
if
(
memberSymbol
.
IsStatic
)
else
if
(
!
memberSymbol
.
RequiresInstanceReciever
)
{
Debug
.
Assert
(!
invokedAsExtensionMethod
||
(
receiverOpt
!=
null
));
...
...
src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
浏览文件 @
393f18b6
...
...
@@ -1672,7 +1672,7 @@ private BoundExpression SynthesizeReceiver(SyntaxNode node, Symbol member, Diagn
// accessor, the result is the same as a member access of the form this.I. This can only
// happen when K is zero.
if
(
member
.
IsStatic
)
if
(
!
member
.
RequiresInstanceReciever
)
{
return
null
;
}
...
...
@@ -1737,7 +1737,7 @@ internal Symbol ContainingMember()
private
BoundExpression
TryBindInteractiveReceiver
(
SyntaxNode
syntax
,
Symbol
currentMember
,
NamedTypeSymbol
currentType
,
NamedTypeSymbol
memberDeclaringType
)
{
if
(
currentType
.
TypeKind
==
TypeKind
.
Submission
&&
!
currentMember
.
IsStatic
)
if
(
currentType
.
TypeKind
==
TypeKind
.
Submission
&&
currentMember
.
RequiresInstanceReciever
)
{
if
(
memberDeclaringType
.
TypeKind
==
TypeKind
.
Submission
)
{
...
...
@@ -6650,7 +6650,7 @@ private void CheckRuntimeSupportForSymbolAccess(SyntaxNode node, BoundExpression
{
bool
?
instanceReceiver
=
IsInstanceReceiver
(
receiver
);
if
(
symbol
.
IsStatic
)
if
(
!
symbol
.
RequiresInstanceReciever
)
{
if
(
instanceReceiver
==
true
)
{
...
...
src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs
浏览文件 @
393f18b6
...
...
@@ -1002,7 +1002,7 @@ private void CheckRestrictedTypeReceiver(BoundExpression expression, Compilation
// instance methods. Therefore we must detect this scenario here, rather than in
// overload resolution.
var
receiver
=
ReplaceTypeOrValueReceiver
(
methodGroup
.
Receiver
,
method
.
IsStatic
&&
!
invokedAsExtensionMethod
,
diagnostics
);
var
receiver
=
ReplaceTypeOrValueReceiver
(
methodGroup
.
Receiver
,
!
method
.
RequiresInstanceReciever
&&
!
invokedAsExtensionMethod
,
diagnostics
);
// Note: we specifically want to do final validation (7.6.5.1) without checking delegate compatibility (15.2),
// so we're calling MethodGroupFinalValidation directly, rather than via MethodGroupConversionHasErrors.
...
...
@@ -1056,7 +1056,7 @@ private void CheckRestrictedTypeReceiver(BoundExpression expression, Compilation
// For extension methods, there is no receiver because the receiver in source was actually the first argument.
// For instance methods, we may have synthesized an implicit this node. We'll keep it for the emitter.
// For static methods, we may have synthesized a type expression. It serves no purpose, so we'll drop it.
if
(
invokedAsExtensionMethod
||
(
method
.
IsStatic
&&
receiver
!=
null
&&
receiver
.
WasCompilerGenerated
))
if
(
invokedAsExtensionMethod
||
(
!
method
.
RequiresInstanceReciever
&&
receiver
!=
null
&&
receiver
.
WasCompilerGenerated
))
{
receiver
=
null
;
}
...
...
@@ -1065,7 +1065,7 @@ private void CheckRestrictedTypeReceiver(BoundExpression expression, Compilation
var
argRefKinds
=
analyzedArguments
.
RefKinds
.
ToImmutableOrNull
();
var
args
=
analyzedArguments
.
Arguments
.
ToImmutable
();
if
(!
gotError
&&
!
method
.
IsStatic
&&
receiver
!=
null
&&
receiver
.
Kind
==
BoundKind
.
ThisReference
&&
receiver
.
WasCompilerGenerated
)
if
(!
gotError
&&
method
.
RequiresInstanceReciever
&&
receiver
!=
null
&&
receiver
.
Kind
==
BoundKind
.
ThisReference
&&
receiver
.
WasCompilerGenerated
)
{
gotError
=
IsRefOrOutThisParameterCaptured
(
node
,
diagnostics
);
}
...
...
@@ -1116,7 +1116,7 @@ private void CheckRestrictedTypeReceiver(BoundExpression expression, Compilation
bool
isDelegateCall
=
(
object
)
delegateTypeOpt
!=
null
;
if
(!
isDelegateCall
)
{
if
(
!
method
.
IsStatic
)
if
(
method
.
RequiresInstanceReciever
)
{
WarnOnAccessOfOffDefault
(
node
.
Kind
()
==
SyntaxKind
.
InvocationExpression
?
((
InvocationExpressionSyntax
)
node
).
Expression
:
...
...
src/Compilers/CSharp/Portable/Binder/Semantics/AccessCheck.cs
浏览文件 @
393f18b6
...
...
@@ -130,7 +130,7 @@ internal static class AccessCheck
case
SymbolKind
.
Property
:
case
SymbolKind
.
Event
:
case
SymbolKind
.
Field
:
if
(
symbol
.
IsStatic
)
if
(
!
symbol
.
RequiresInstanceReciever
)
{
// static members aren't accessed "through" an "instance" of any type. So we
// null out the "through" instance here. This ensures that we'll understand
...
...
src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/Conversions.cs
浏览文件 @
393f18b6
...
...
@@ -276,7 +276,7 @@ private static Conversion ToConversion(OverloadResolutionResult<MethodSymbol> re
}
//cannot capture stack-only types.
if
(
!
method
.
IsStatic
&&
methodGroup
.
Receiver
?.
Type
?.
IsRestrictedType
()
==
true
)
if
(
method
.
RequiresInstanceReciever
&&
methodGroup
.
Receiver
?.
Type
?.
IsRestrictedType
()
==
true
)
{
return
Conversion
.
NoConversion
;
}
...
...
src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/OverloadResolution.cs
浏览文件 @
393f18b6
...
...
@@ -337,7 +337,7 @@ private static bool OverloadResolutionResultIsValid<TMember>(ArrayBuilder<Member
{
var
result
=
results
[
f
];
TMember
member
=
result
.
Member
;
if
(
result
.
Result
.
IsValid
&&
member
.
IsStatic
!
=
keepStatic
)
if
(
result
.
Result
.
IsValid
&&
member
.
RequiresInstanceReciever
=
=
keepStatic
)
{
results
[
f
]
=
new
MemberResolutionResult
<
TMember
>(
member
,
result
.
LeastOverriddenMember
,
MemberAnalysisResult
.
StaticInstanceMismatch
());
}
...
...
src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/OverloadResolutionResult.cs
浏览文件 @
393f18b6
...
...
@@ -608,9 +608,11 @@ private bool UseSiteError()
else
{
ErrorCode
errorCode
=
symbol
.
IsStatic
?
ErrorCode
.
ERR_ObjectProhibited
:
Binder
.
WasImplicitReceiver
(
receiverOpt
)
&&
binder
.
InFieldInitializer
&&
!
binder
.
BindingTopLevelScriptCode
?
ErrorCode
.
ERR_FieldInitRefNonstatic
:
ErrorCode
.
ERR_ObjectRequired
;
symbol
.
RequiresInstanceReciever
?
Binder
.
WasImplicitReceiver
(
receiverOpt
)
&&
binder
.
InFieldInitializer
&&
!
binder
.
BindingTopLevelScriptCode
?
ErrorCode
.
ERR_FieldInitRefNonstatic
:
ErrorCode
.
ERR_ObjectRequired
:
ErrorCode
.
ERR_ObjectProhibited
;
// error CS0176: Member 'Program.M(B)' cannot be accessed with an instance reference; qualify it with a type name instead
// -or-
// error CS0120: An object reference is required for the non-static field, method, or property 'Program.M(B)'
...
...
src/Compilers/CSharp/Portable/CodeGen/EmitExpression.cs
浏览文件 @
393f18b6
...
...
@@ -1479,7 +1479,7 @@ private void EmitCallExpression(BoundCall call, UseKind useKind)
CallKind
callKind
;
if
(
method
.
IsStatic
)
if
(
!
method
.
RequiresInstanceReciever
)
{
callKind
=
CallKind
.
Call
;
}
...
...
@@ -1748,7 +1748,7 @@ private static int GetCallStackBehavior(BoundCall call)
stack
+=
1
;
}
if
(
!
call
.
Method
.
IsStatic
)
if
(
call
.
Method
.
RequiresInstanceReciever
)
{
// The call pops the receiver off the stack.
stack
-=
1
;
...
...
src/Compilers/CSharp/Portable/CodeGen/Optimizer.cs
浏览文件 @
393f18b6
...
...
@@ -1107,7 +1107,7 @@ public override BoundNode VisitCall(BoundCall node)
// matches or a bit stronger than EmitReceiverRef
// if there are any doubts that receiver is a ref type,
// assume we will need an address (that will prevent scheduling of receiver).
if
(
!
node
.
Method
.
IsStatic
)
if
(
node
.
Method
.
RequiresInstanceReciever
)
{
receiver
=
VisitCallReceiver
(
receiver
);
}
...
...
src/Compilers/CSharp/Portable/FlowAnalysis/AbstractFlowPass.cs
浏览文件 @
393f18b6
...
...
@@ -1139,7 +1139,7 @@ private void VisitReceiverBeforeCall(BoundExpression receiverOpt, MethodSymbol m
private
void
VisitReceiverAfterCall
(
BoundExpression
receiverOpt
,
MethodSymbol
method
)
{
NamedTypeSymbol
containingType
;
if
(
receiverOpt
!=
null
&&
((
object
)
method
==
null
||
method
.
MethodKind
==
MethodKind
.
Constructor
||
(
object
)(
containingType
=
method
.
ContainingType
)
!=
null
&&
!
method
.
IsStatic
&&
!
containingType
.
IsReferenceType
&&
!
TypeIsImmutable
(
containingType
)))
if
(
receiverOpt
!=
null
&&
((
object
)
method
==
null
||
method
.
MethodKind
==
MethodKind
.
Constructor
||
(
object
)(
containingType
=
method
.
ContainingType
)
!=
null
&&
method
.
RequiresInstanceReciever
&&
!
containingType
.
IsReferenceType
&&
!
TypeIsImmutable
(
containingType
)))
{
WriteArgument
(
receiverOpt
,
method
?.
MethodKind
==
MethodKind
.
Constructor
?
RefKind
.
Out
:
RefKind
.
Ref
,
method
);
}
...
...
@@ -1296,7 +1296,7 @@ public override BoundNode VisitDelegateCreationExpression(BoundDelegateCreationE
var
methodGroup
=
node
.
Argument
as
BoundMethodGroup
;
if
(
methodGroup
!=
null
)
{
if
((
object
)
node
.
MethodOpt
!=
null
&&
!
node
.
MethodOpt
.
IsStatic
)
if
((
object
)
node
.
MethodOpt
!=
null
&&
node
.
MethodOpt
.
RequiresInstanceReciever
)
{
if
(
_trackRegions
)
{
...
...
@@ -1377,7 +1377,7 @@ public override BoundNode VisitConversion(BoundConversion node)
{
if
(
node
.
ConversionKind
==
ConversionKind
.
MethodGroup
)
{
if
(
node
.
IsExtensionMethod
||
((
object
)
node
.
SymbolOpt
!=
null
&&
!
node
.
SymbolOpt
.
IsStatic
))
if
(
node
.
IsExtensionMethod
||
((
object
)
node
.
SymbolOpt
!=
null
&&
node
.
SymbolOpt
.
RequiresInstanceReciever
))
{
BoundExpression
receiver
=
((
BoundMethodGroup
)
node
.
Operand
).
ReceiverOpt
;
// A method group's "implicit this" is only used for instance methods.
...
...
src/Compilers/CSharp/Portable/FlowAnalysis/LocalDataFlowPass.cs
浏览文件 @
393f18b6
...
...
@@ -217,7 +217,7 @@ protected virtual int MakeSlot(BoundExpression node)
case
BoundKind
.
PropertyAccess
:
if
(
TryGetReceiverAndMember
(
node
,
out
BoundExpression
receiver
,
out
Symbol
member
))
{
Debug
.
Assert
((
receiver
is
null
)
==
member
.
IsStatic
);
Debug
.
Assert
((
receiver
is
null
)
!=
member
.
RequiresInstanceReciever
);
return
MakeMemberSlot
(
receiver
,
member
);
}
break
;
...
...
@@ -230,7 +230,7 @@ protected virtual int MakeSlot(BoundExpression node)
protected
int
MakeMemberSlot
(
BoundExpression
receiverOpt
,
Symbol
member
)
{
int
containingSlot
=
-
1
;
if
(
!
member
.
IsStatic
)
if
(
member
.
RequiresInstanceReciever
)
{
if
(
receiverOpt
is
null
)
{
...
...
src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs
浏览文件 @
393f18b6
...
...
@@ -621,7 +621,7 @@ protected override bool TryGetReceiverAndMember(BoundExpression expr, out BoundE
}
}
Debug
.
Assert
(
member
?.
IsStatic
!=
true
);
Debug
.
Assert
(
member
?.
RequiresInstanceReciever
??
true
);
return
(
object
)
member
!=
null
&&
(
object
)
receiver
!=
null
&&
...
...
@@ -2737,7 +2737,7 @@ private TypeWithState VisitCallReceiver(BoundCall node)
var
type
=
receiverType
.
Type
;
var
method
=
node
.
Method
;
if
(
!
method
.
IsStatic
&&
if
(
method
.
RequiresInstanceReciever
&&
type
?.
IsNullableType
()
==
true
&&
method
.
ContainingType
.
IsReferenceType
)
{
...
...
@@ -5371,7 +5371,7 @@ private void VisitMemberAccess(BoundExpression node, BoundExpression receiverOpt
var
receiverType
=
(
receiverOpt
!=
null
)
?
VisitRvalueWithState
(
receiverOpt
)
:
default
;
SpecialMember
?
nullableOfTMember
=
null
;
if
(
!
member
.
IsStatic
)
if
(
member
.
RequiresInstanceReciever
)
{
member
=
AsMemberOfType
(
receiverType
.
Type
,
member
);
nullableOfTMember
=
GetNullableOfTMember
(
member
);
...
...
src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker_Patterns.cs
浏览文件 @
393f18b6
...
...
@@ -229,7 +229,7 @@ protected override LocalState VisitSwitchStatementDispatch(BoundSwitchStatement
// We may need to recompute the Deconstruct method for a deconstruction if
// the receiver type has changed (e.g. its nested nullability).
var
method
=
e
.
DeconstructMethod
;
int
extensionExtra
=
method
.
IsStatic
?
1
:
0
;
int
extensionExtra
=
method
.
RequiresInstanceReciever
?
0
:
1
;
for
(
int
i
=
0
;
i
<
method
.
ParameterCount
-
extensionExtra
;
i
++)
{
var
parameterType
=
method
.
Parameters
[
i
+
extensionExtra
].
TypeWithAnnotations
;
...
...
src/Compilers/CSharp/Portable/Lowering/DiagnosticsPass_ExpressionTrees.cs
浏览文件 @
393f18b6
...
...
@@ -90,7 +90,7 @@ public override BoundNode VisitSizeOfOperator(BoundSizeOfOperator node)
public
override
BoundNode
VisitLocalFunctionStatement
(
BoundLocalFunctionStatement
node
)
{
var
outerLocalFunction
=
_staticLocalFunction
;
if
(
node
.
Symbol
.
IsStatic
LocalFunction
)
if
(
node
.
Symbol
.
IsStatic
)
{
_staticLocalFunction
=
node
.
Symbol
;
}
...
...
src/Compilers/CSharp/Portable/Lowering/LambdaRewriter/ExpressionLambdaRewriter.cs
浏览文件 @
393f18b6
...
...
@@ -564,7 +564,7 @@ private BoundExpression VisitCall(BoundCall node)
var
method
=
node
.
Method
;
return
ExprFactory
(
"Call"
,
method
.
IsStatic
?
_bound
.
Null
(
ExpressionType
)
:
Visit
(
node
.
ReceiverOpt
),
method
.
RequiresInstanceReciever
?
Visit
(
node
.
ReceiverOpt
)
:
_bound
.
Null
(
ExpressionType
),
_bound
.
MethodInfo
(
method
),
Expressions
(
node
.
Arguments
));
}
...
...
@@ -608,7 +608,7 @@ private BoundExpression VisitConversion(BoundConversion node)
case
ConversionKind
.
MethodGroup
:
{
var
mg
=
(
BoundMethodGroup
)
node
.
Operand
;
return
DelegateCreation
(
mg
.
ReceiverOpt
,
node
.
SymbolOpt
,
node
.
Type
,
node
.
SymbolOpt
.
IsStatic
&&
!
node
.
IsExtensionMethod
);
return
DelegateCreation
(
mg
.
ReceiverOpt
,
node
.
SymbolOpt
,
node
.
Type
,
!
node
.
SymbolOpt
.
RequiresInstanceReciever
&&
!
node
.
IsExtensionMethod
);
}
case
ConversionKind
.
ExplicitUserDefined
:
case
ConversionKind
.
ImplicitUserDefined
:
...
...
@@ -665,10 +665,10 @@ private BoundExpression Convert(BoundExpression expr, TypeSymbol type, bool isCh
return
ExprFactory
(
isChecked
?
"ConvertChecked"
:
"Convert"
,
expr
,
_bound
.
Typeof
(
type
));
}
private
BoundExpression
DelegateCreation
(
BoundExpression
receiver
,
MethodSymbol
method
,
TypeSymbol
delegateType
,
bool
staticMemb
er
)
private
BoundExpression
DelegateCreation
(
BoundExpression
receiver
,
MethodSymbol
method
,
TypeSymbol
delegateType
,
bool
requiresInstanceReciev
er
)
{
var
nullObject
=
_bound
.
Null
(
_objectType
);
receiver
=
staticMemb
er
?
nullObject
:
receiver
.
Type
.
IsReferenceType
?
receiver
:
_bound
.
Convert
(
_objectType
,
receiver
);
receiver
=
requiresInstanceReciev
er
?
nullObject
:
receiver
.
Type
.
IsReferenceType
?
receiver
:
_bound
.
Convert
(
_objectType
,
receiver
);
var
createDelegate
=
_bound
.
WellKnownMethod
(
WellKnownMember
.
System_Reflection_MethodInfo__CreateDelegate
,
isOptional
:
true
);
BoundExpression
unquoted
;
...
...
@@ -700,7 +700,7 @@ private BoundExpression VisitDelegateCreationExpression(BoundDelegateCreationExp
if
((
object
)
node
.
MethodOpt
!=
null
)
{
bool
staticMember
=
node
.
MethodOpt
.
IsStatic
&&
!
node
.
IsExtensionMethod
;
bool
staticMember
=
!
node
.
MethodOpt
.
RequiresInstanceReciever
&&
!
node
.
IsExtensionMethod
;
return
DelegateCreation
(
node
.
Argument
,
node
.
MethodOpt
,
node
.
Type
,
staticMember
);
}
...
...
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Call.cs
浏览文件 @
393f18b6
...
...
@@ -44,11 +44,11 @@ public BoundExpression VisitDynamicInvocation(BoundDynamicInvocation node, bool
{
// Calling a static method defined on an outer class via its simple name.
NamedTypeSymbol
firstContainer
=
node
.
ApplicableMethods
.
First
().
ContainingType
;
Debug
.
Assert
(
node
.
ApplicableMethods
.
All
(
m
=>
m
.
IsStatic
&&
TypeSymbol
.
Equals
(
m
.
ContainingType
,
firstContainer
,
TypeCompareKind
.
ConsiderEverything2
)));
Debug
.
Assert
(
node
.
ApplicableMethods
.
All
(
m
=>
!
m
.
RequiresInstanceReciever
&&
TypeSymbol
.
Equals
(
m
.
ContainingType
,
firstContainer
,
TypeCompareKind
.
ConsiderEverything2
)));
loweredReceiver
=
new
BoundTypeExpression
(
node
.
Syntax
,
null
,
firstContainer
);
}
else
if
(
hasImplicitReceiver
&&
_factory
.
TopLevelMethod
.
IsStatic
)
else
if
(
hasImplicitReceiver
&&
!
_factory
.
TopLevelMethod
.
RequiresInstanceReciever
)
{
// Calling a static method defined on the current class via its simple name.
loweredReceiver
=
new
BoundTypeExpression
(
node
.
Syntax
,
null
,
_factory
.
CurrentType
);
...
...
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Conversion.cs
浏览文件 @
393f18b6
...
...
@@ -351,7 +351,7 @@ private static bool IsFloatingPointExpressionOfUnknownPrecision(BoundExpression
Debug
.
Assert
((
object
)
method
!=
null
);
var
oldSyntax
=
_factory
.
Syntax
;
_factory
.
Syntax
=
(
mg
.
ReceiverOpt
??
mg
).
Syntax
;
var
receiver
=
(
method
.
IsStatic
&&
!
oldNode
.
IsExtensionMethod
)
?
_factory
.
Type
(
method
.
ContainingType
)
:
mg
.
ReceiverOpt
;
var
receiver
=
(
!
method
.
RequiresInstanceReciever
&&
!
oldNode
.
IsExtensionMethod
)
?
_factory
.
Type
(
method
.
ContainingType
)
:
mg
.
ReceiverOpt
;
_factory
.
Syntax
=
oldSyntax
;
return
new
BoundDelegateCreationExpression
(
syntax
,
argument
:
receiver
,
methodOpt
:
method
,
isExtensionMethod
:
oldNode
.
IsExtensionMethod
,
type
:
rewrittenType
);
...
...
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_DelegateCreationExpression.cs
浏览文件 @
393f18b6
...
...
@@ -27,7 +27,7 @@ public override BoundNode VisitDelegateCreationExpression(BoundDelegateCreationE
var
method
=
node
.
MethodOpt
;
var
oldSyntax
=
_factory
.
Syntax
;
_factory
.
Syntax
=
(
mg
.
ReceiverOpt
??
mg
).
Syntax
;
var
receiver
=
(
method
.
IsStatic
&&
!
node
.
IsExtensionMethod
)
?
_factory
.
Type
(
method
.
ContainingType
)
:
VisitExpression
(
mg
.
ReceiverOpt
);
var
receiver
=
(
!
method
.
RequiresInstanceReciever
&&
!
node
.
IsExtensionMethod
)
?
_factory
.
Type
(
method
.
ContainingType
)
:
VisitExpression
(
mg
.
ReceiverOpt
);
_factory
.
Syntax
=
oldSyntax
;
return
node
.
Update
(
receiver
,
method
,
node
.
IsExtensionMethod
,
node
.
Type
);
}
...
...
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LoweredDynamicOperationFactory.cs
浏览文件 @
393f18b6
...
...
@@ -197,7 +197,7 @@ private enum CSharpArgumentInfoFlags
_factory
.
Syntax
=
loweredReceiver
.
Syntax
;
CSharpBinderFlags
binderFlags
=
0
;
if
(
hasImplicitReceiver
&&
!
_factory
.
TopLevelMethod
.
IsStatic
)
if
(
hasImplicitReceiver
&&
_factory
.
TopLevelMethod
.
RequiresInstanceReciever
)
{
binderFlags
|=
CSharpBinderFlags
.
InvokeSimpleName
;
}
...
...
src/Compilers/CSharp/Portable/Lowering/SpillSequenceSpiller.cs
浏览文件 @
393f18b6
...
...
@@ -764,7 +764,7 @@ public override BoundNode VisitCall(BoundCall node)
{
receiver
=
VisitExpression
(
ref
builder
,
node
.
ReceiverOpt
);
}
else
if
(
!
node
.
Method
.
IsStatic
)
else
if
(
node
.
Method
.
RequiresInstanceReciever
)
{
// spill the receiver if there were await expressions in the arguments
var
receiverBuilder
=
new
BoundSpillSequenceBuilder
();
...
...
src/Compilers/CSharp/Portable/Symbols/MethodSymbol.cs
浏览文件 @
393f18b6
...
...
@@ -1100,7 +1100,7 @@ ITypeSymbol IMethodSymbol.ReceiverType
CodeAnalysis
.
NullableAnnotation
IMethodSymbol
.
ReceiverNullableAnnotation
=>
ReceiverNullableAnnotation
;
protected
virtual
CodeAnalysis
.
NullableAnnotation
ReceiverNullableAnnotation
=>
IsStatic
?
CodeAnalysis
.
NullableAnnotation
.
NotApplicable
:
CodeAnalysis
.
NullableAnnotation
.
NotAnnotated
;
RequiresInstanceReciever
?
CodeAnalysis
.
NullableAnnotation
.
NotAnnotated
:
CodeAnalysis
.
NullableAnnotation
.
NotApplicable
;
IMethodSymbol
IMethodSymbol
.
ReducedFrom
{
...
...
src/Compilers/CSharp/Portable/Symbols/Source/LocalFunctionSymbol.cs
浏览文件 @
393f18b6
...
...
@@ -45,7 +45,6 @@ internal sealed class LocalFunctionSymbol : SourceMethodSymbol
_declarationModifiers
=
DeclarationModifiers
.
Private
|
DeclarationModifiers
.
Static
|
syntax
.
Modifiers
.
ToDeclarationModifiers
(
diagnostics
:
_declarationDiagnostics
);
this
.
CheckUnsafeModifier
(
_declarationModifiers
,
_declarationDiagnostics
);
...
...
@@ -128,6 +127,8 @@ internal void GetDeclarationDiagnostics(DiagnosticBag addTo)
internal
override
void
AddDeclarationDiagnostics
(
DiagnosticBag
diagnostics
)
=>
_declarationDiagnostics
.
AddRange
(
diagnostics
);
public
override
bool
RequiresInstanceReciever
=>
false
;
public
override
bool
IsVararg
{
get
...
...
@@ -286,9 +287,6 @@ public override bool IsExtensionMethod
}
}
// Replace with IsStatic after fixing https://github.com/dotnet/roslyn/issues/27719.
internal
bool
IsStaticLocalFunction
=>
_syntax
.
Modifiers
.
Any
(
SyntaxKind
.
StaticKeyword
);
internal
override
TypeWithAnnotations
IteratorElementTypeWithAnnotations
{
get
...
...
src/Compilers/CSharp/Portable/Symbols/Symbol.cs
浏览文件 @
393f18b6
...
...
@@ -346,6 +346,11 @@ internal static ImmutableArray<SyntaxReference> GetDeclaringSyntaxReferenceHelpe
/// </summary>
public
abstract
bool
IsStatic
{
get
;
}
/// <summary>
/// Returns true if this symbol requires an instance reference as the implicit reciever. This is false if the symbol is static, or a <see cref="LocalFunctionSymbol"/>
/// </summary>
public
virtual
bool
RequiresInstanceReciever
=>
!
IsStatic
;
/// <summary>
/// Returns true if this symbol is "virtual", has an implementation, and does not override a
/// base class member; i.e., declared with the <c>virtual</c> modifier. Does not return true for
...
...
src/Compilers/CSharp/Portable/Symbols/Wrapped/WrappedMethodSymbol.cs
浏览文件 @
393f18b6
...
...
@@ -110,6 +110,14 @@ public override bool IsStatic
}
}
public
override
bool
RequiresInstanceReciever
{
get
{
return
UnderlyingMethod
.
RequiresInstanceReciever
;
}
}
public
override
bool
IsVirtual
{
get
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录