diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs index 06ea5f338d14db4bfe9227203ac04a80a712d81e..edb7704841b704d33298d7a323b32e5d349f3160 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs @@ -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 = diff --git a/src/Compilers/CSharp/Portable/FlowAnalysis/PreciseAbstractFlowPass.cs b/src/Compilers/CSharp/Portable/FlowAnalysis/PreciseAbstractFlowPass.cs index b3b4b56801ef847e79059fdbf976996efd7f77b7..3c31cf01f749a7107a51889d3d2be277c1f78edf 100644 --- a/src/Compilers/CSharp/Portable/FlowAnalysis/PreciseAbstractFlowPass.cs +++ b/src/Compilers/CSharp/Portable/FlowAnalysis/PreciseAbstractFlowPass.cs @@ -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); diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NameOfTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NameOfTests.cs index f5deb19a620bde0dbeb157094ca56479212d7bb8..f25c1b5f18e080d463e7eb580cfe46f75546a3f2 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NameOfTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NameOfTests.cs @@ -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(); + } } }