提交 c3fa51de 编写于 作者: T Ty Overby 提交者: GitHub

ignore fixed-field check if inside nameof binder (#13941)

* ignore fixed-field check if inside nameof binder

* redo is nameof-binder strategy

* pick a good name for the test

* use existing method for determining if we are inside of a nameof node

* fix nameof(outer field) crash

* minor style tweaks

* allow nulls in VisitLValue

* harden vb VisitLValue/VisitRValue

* Revert "harden vb VisitLValue/VisitRValue"

This reverts commit edeaddd00ce310b0408b5fc6609b15f17b674654.
上级 c8427c03
......@@ -5664,7 +5664,7 @@ private static void CombineExtensionMethodArguments(BoundExpression receiver, An
hasError = this.CheckInstanceOrStatic(node, receiver, fieldSymbol, ref resultKind, diagnostics);
}
if (!hasError && fieldSymbol.IsFixed)
if (!hasError && fieldSymbol.IsFixed && EnclosingNameofArgument == null)
{
TypeSymbol receiverType = receiver.Type;
hasError =
......
......@@ -501,7 +501,7 @@ protected void SetUnreachable()
protected void VisitLvalue(BoundExpression node)
{
if (_trackRegions && node == this.firstInRegion && this.regionPlace == RegionPlace.Before) EnterRegion();
switch (node.Kind)
switch (node?.Kind)
{
case BoundKind.Parameter:
VisitLvalueParameter((BoundParameter)node);
......
......@@ -1209,7 +1209,7 @@ class Other {
}
";
var compilation = CreateCompilationWithMscorlib45(source, null, new CSharpCompilationOptions(OutputKind.ConsoleApplication).WithAllowUnsafe(true));
CompileAndVerify(compilation, expectedOutput:
CompileAndVerify(compilation, expectedOutput:
"MessageType x MessageType").VerifyDiagnostics();
}
......@@ -1258,5 +1258,73 @@ class Other {
// return nameof(myStruct.MessageType);
Diagnostic(ErrorCode.ERR_BadArgType, "myStruct.MessageType").WithArguments("1", "char*", "char[]").WithLocation(26, 23));
}
[Fact, WorkItem(12696, "https://github.com/dotnet/roslyn/issues/12696")]
public void FixedFieldAccessInsideNameOf()
{
var source =
@"
using System;
struct MyType
{
public static string a = nameof(MyType.normalField);
public static string b = nameof(MyType.fixedField);
public static string c = nameof(fixedField);
public int normalField;
public unsafe fixed short fixedField[6];
public MyType(int i) {
this.normalField = i;
}
}
class EntryPoint
{
public static void Main(string[] args)
{
Console.Write(MyType.a + "" "");
Console.Write(MyType.b + "" "");
Console.Write(MyType.c);
}
}
";
var compilation = CreateCompilationWithMscorlib45(source, null, new CSharpCompilationOptions(OutputKind.ConsoleApplication).WithAllowUnsafe(true));
CompileAndVerify(compilation, expectedOutput: "normalField fixedField fixedField").VerifyDiagnostics();
}
[Fact, WorkItem(12696, "https://github.com/dotnet/roslyn/issues/12696")]
public void FixedFieldAccessFromInnerClass()
{
var source =
@"
using System;
public struct MyType
{
public static class Inner
{
public static string a = nameof(normalField);
public static string b = nameof(fixedField);
}
public int normalField;
public unsafe fixed short fixedField[6];
}
class EntryPoint
{
public static void Main(string[] args)
{
Console.Write(MyType.Inner.a + "" "");
Console.Write(MyType.Inner.b);
}
}
";
var compilation = CreateCompilationWithMscorlib45(source, null, new CSharpCompilationOptions(OutputKind.ConsoleApplication).WithAllowUnsafe(true));
CompileAndVerify(compilation, expectedOutput: "normalField fixedField").VerifyDiagnostics();
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册