提交 402aca3d 编写于 作者: V vsadov

Fixes:#24627

上级 b410ccf1
......@@ -3377,16 +3377,19 @@ private static bool IsNegativeConstantForArraySize(BoundExpression expression)
var refKinds = analyzedArguments.RefKinds.ToImmutableOrNull();
var argsToParamsOpt = memberResolutionResult.Result.ArgsToParamsOpt;
hasErrors |= !CheckInvocationArgMixing(
nonNullSyntax,
resultMember,
receiver,
resultMember.Parameters,
arguments,
refKinds,
argsToParamsOpt,
this.LocalScopeDepth,
diagnostics);
if (!hasErrors)
{
hasErrors = !CheckInvocationArgMixing(
nonNullSyntax,
resultMember,
receiver,
resultMember.Parameters,
arguments,
refKinds,
argsToParamsOpt,
this.LocalScopeDepth,
diagnostics);
}
return new BoundCall(
nonNullSyntax,
......@@ -4491,16 +4494,20 @@ private bool IsConstructorAccessible(MethodSymbol constructor, ref HashSet<Diagn
var arguments = analyzedArguments.Arguments.ToImmutable();
var refKinds = analyzedArguments.RefKinds.ToImmutableOrNull();
var argToParams = memberResolutionResult.Result.ArgsToParamsOpt;
hasError |= !CheckInvocationArgMixing(
node,
method,
null,
method.Parameters,
arguments,
refKinds,
argToParams,
this.LocalScopeDepth,
diagnostics);
if (!hasError)
{
hasError = !CheckInvocationArgMixing(
node,
method,
null,
method.Parameters,
arguments,
refKinds,
argToParams,
this.LocalScopeDepth,
diagnostics);
}
result = new BoundObjectCreationExpression(
node,
......@@ -6816,16 +6823,20 @@ private BoundExpression BindIndexedPropertyAccess(SyntaxNode syntax, BoundExpres
}
var arguments = analyzedArguments.Arguments.ToImmutable();
gotError |= !CheckInvocationArgMixing(
syntax,
property,
receiver,
property.Parameters,
arguments,
argumentRefKinds,
argsToParams,
this.LocalScopeDepth,
diagnostics);
if (!gotError)
{
gotError = !CheckInvocationArgMixing(
syntax,
property,
receiver,
property.Parameters,
arguments,
argumentRefKinds,
argsToParams,
this.LocalScopeDepth,
diagnostics);
}
propertyAccess = new BoundIndexerAccess(
syntax,
......
......@@ -1066,16 +1066,19 @@ private static void CheckRestrictedTypeReceiver(BoundExpression expression, Comp
Debug.Assert(args.IsDefaultOrEmpty || (object)receiver != (object)args[0]);
gotError |= !CheckInvocationArgMixing(
node,
method,
receiver,
method.Parameters,
args,
argRefKinds,
argsToParams,
this.LocalScopeDepth,
diagnostics);
if (!gotError)
{
gotError = !CheckInvocationArgMixing(
node,
method,
receiver,
method.Parameters,
args,
argRefKinds,
argsToParams,
this.LocalScopeDepth,
diagnostics);
}
if ((object)delegateTypeOpt != null)
{
......
......@@ -1382,5 +1382,41 @@ void Check()
// public static Point field1;
Diagnostic(ErrorCode.ERR_FieldAutoPropCantBeByRefLike, "Point").WithArguments("Point").WithLocation(7, 19));
}
[Fact]
[WorkItem(24627, "https://github.com/dotnet/roslyn/issues/24627")]
public void ArgMixingBogusInstanceCall()
{
var comp = CreateCompilationWithMscorlibAndSpan(@"
class Program
{
ref struct S1
{
public void Test(int x) => throw null;
public int this[int x] => throw null;
public S1(S1 x, int y) => throw null;
}
static void Main()
{
// these are all errors, we should not be doing escape analysis on them.
S1.Test(1);
var x = S1[1];
var y = new S1(S1, 1);
}
}");
comp.VerifyDiagnostics(
// (14,9): error CS0120: An object reference is required for the non-static field, method, or property 'Program.S1.Test(int)'
// S1.Test(1);
Diagnostic(ErrorCode.ERR_ObjectRequired, "S1.Test").WithArguments("Program.S1.Test(int)").WithLocation(14, 9),
// (15,17): error CS0119: 'Program.S1' is a type, which is not valid in the given context
// var x = S1[1];
Diagnostic(ErrorCode.ERR_BadSKunknown, "S1").WithArguments("Program.S1", "type").WithLocation(15, 17),
// (16,24): error CS0119: 'Program.S1' is a type, which is not valid in the given context
// var y = new S1(S1, 1);
Diagnostic(ErrorCode.ERR_BadSKunknown, "S1").WithArguments("Program.S1", "type").WithLocation(16, 24)
);
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册