提交 f1cec151 编写于 作者: M Matt Warren

Merge remote-tracking branch 'dotnet/master' into ReenableTests

......@@ -239,11 +239,13 @@ private bool IsFixedBuffer(out int fixedSize, out TypeSymbol fixedElementType)
if (containingPEModule.Module.HasFixedBufferAttribute(_handle, out elementTypeName, out bufferSize))
{
var decoder = new MetadataDecoder(containingPEModule);
var elementType = decoder.GetTypeSymbolForSerializedType(elementTypeName);
if (elementType.FixedBufferElementSizeInBytes() != 0)
var specialTypeName = MetadataHelpers.DecodeTypeName(elementTypeName).TopLevelType;
var specialType = SpecialTypes.GetTypeFromMetadataName(specialTypeName);
if (specialType != SpecialType.None &&
specialType.FixedBufferElementSizeInBytes() != 0)
{
fixedSize = bufferSize;
fixedElementType = elementType;
fixedElementType = decoder.GetSpecialType(specialType);
return true;
}
}
......
......@@ -36,6 +36,54 @@ private static string GetEscapedNewLine()
#region Unsafe regions
[Fact]
public void FixedSizeBuffer()
{
var text1 = @"
using System;
using System.Runtime.InteropServices;
public static class R
{
public unsafe struct S
{
public fixed byte Buffer[16];
}
}";
var comp1 = CreateCompilation(text1, assemblyName: "assembly1", references: new[] { MscorlibRef_v20 },
options: TestOptions.UnsafeDebugDll);
var ref1 = comp1.EmitToImageReference();
var text2 = @"
using System;
class C
{
unsafe void M(byte* p)
{
R.S* p2 = (R.S*)p;
IntPtr p3 = M2((IntPtr)p2[0].Buffer);
}
unsafe IntPtr M2(IntPtr p) => p;
}";
var comp2 = CreateCompilationWithMscorlib45(text2,
references: new[] { ref1 },
options: TestOptions.UnsafeDebugDll);
comp2.VerifyDiagnostics(
// warning CS1701: Assuming assembly reference 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' used by 'assembly1' matches identity 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' of 'mscorlib', you may need to supply runtime policy
Diagnostic(ErrorCode.WRN_UnifyReferenceMajMin).WithArguments("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "assembly1", "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "mscorlib").WithLocation(1, 1),
// warning CS1701: Assuming assembly reference 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' used by 'assembly1' matches identity 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' of 'mscorlib', you may need to supply runtime policy
Diagnostic(ErrorCode.WRN_UnifyReferenceMajMin).WithArguments("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "assembly1", "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "mscorlib").WithLocation(1, 1),
// warning CS1701: Assuming assembly reference 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' used by 'assembly1' matches identity 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' of 'mscorlib', you may need to supply runtime policy
Diagnostic(ErrorCode.WRN_UnifyReferenceMajMin).WithArguments("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "assembly1", "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "mscorlib").WithLocation(1, 1),
// warning CS1701: Assuming assembly reference 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' used by 'assembly1' matches identity 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' of 'mscorlib', you may need to supply runtime policy
Diagnostic(ErrorCode.WRN_UnifyReferenceMajMin).WithArguments("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "assembly1", "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "mscorlib").WithLocation(1, 1),
// warning CS1701: Assuming assembly reference 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' used by 'assembly1' matches identity 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' of 'mscorlib', you may need to supply runtime policy
Diagnostic(ErrorCode.WRN_UnifyReferenceMajMin).WithArguments("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "assembly1", "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "mscorlib").WithLocation(1, 1));
}
[Fact]
public void CompilationNotUnsafe1()
{
......
......@@ -70,7 +70,7 @@ protected TypeSymbol MakePointerTypeSymbol(TypeSymbol type, ImmutableArray<Modif
return _factory.MakePointerTypeSymbol(this.moduleSymbol, type, customModifiers);
}
protected TypeSymbol GetSpecialType(SpecialType specialType)
internal TypeSymbol GetSpecialType(SpecialType specialType)
{
return _factory.GetSpecialType(this.moduleSymbol, specialType);
}
......
......@@ -118,9 +118,11 @@ internal class Indenter : AbstractIndenter
{
return GetIndentationFromCommaSeparatedList(previousToken);
}
// okay, beginning of the line is not trivia, use the last token on the line as base token
return GetIndentationBasedOnToken(token);
else if (!previousToken.IsKind(SyntaxKind.None))
{
// okay, beginning of the line is not trivia, use the last token on the line as base token
return GetIndentationBasedOnToken(token);
}
}
// this case we will keep the indentation of this trivia line
......
......@@ -95,6 +95,20 @@ public void UsingDirective()
expectedIndentation: 0);
}
[Fact]
[Trait(Traits.Feature, Traits.Features.SmartIndent)]
public void AfterTopOfFileComment()
{
var code = @"// comment
class
";
AssertIndentNotUsingSmartTokenFormatterButUsingIndenter(
code,
indentationLine: 2,
expectedIndentation: 0);
}
[Fact]
[Trait(Traits.Feature, Traits.Features.SmartIndent)]
public void DottedName()
......
......@@ -1198,6 +1198,25 @@ class Class
AutoFormatOnSemicolon(code, expected, SyntaxKind.OpenBraceToken);
}
[Fact]
[Trait(Traits.Feature, Traits.Features.SmartTokenFormatting)]
public void ExpressionValuedPropertyInitializer()
{
var code = @"using System;
class Class
{
public int Three => 1+2;$$
";
var expected = @"using System;
class Class
{
public int Three => 1 + 2;
";
AutoFormatOnSemicolon(code, expected, SyntaxKind.OpenBraceToken);
}
[Fact]
[Trait(Traits.Feature, Traits.Features.SmartTokenFormatting)]
public void EmbeddedStatement10()
......
......@@ -13,6 +13,7 @@
using System.Runtime.InteropServices;
using Xunit;
using Roslyn.Test.PdbUtilities;
using Microsoft.CodeAnalysis.CSharp.Symbols;
namespace Microsoft.CodeAnalysis.CSharp.UnitTests
{
......@@ -609,8 +610,70 @@ void M()
out errorMessage);
Assert.Equal(2, numRetries); // Ensure that we actually retried and that we bailed out on the second retry if the same identity was seen in the diagnostics.
Assert.Equal($"error CS0012: The type 'MissingType' is defined in an assembly that is not referenced. You must add a reference to assembly '{missingIdentity}'.", errorMessage);
}
Assert.Equal($"error CS0012: The type 'MissingType' is defined in an assembly that is not referenced. You must add a reference to assembly '{missingIdentity}'.", errorMessage);
}
[WorkItem(1151888)]
[Fact]
public void SucceedOnRetry()
{
var source = @"
class C
{
void M()
{
}
}";
var comp = CreateCompilationWithMscorlib(source);
var runtime = CreateRuntimeInstance(comp);
var context = CreateMethodContext(runtime, "C.M");
var missingModule = runtime.Modules.First();
var missingIdentity = missingModule.MetadataReader.ReadAssemblyIdentityOrThrow();
var shouldSucceed = false;
string errorMessage;
var compileResult = ExpressionCompilerTestHelpers.CompileExpressionWithRetry(
runtime.Modules.Select(m => m.MetadataBlock).ToImmutableArray(),
context,
(_, diagnostics) =>
{
if (shouldSucceed)
{
return TestCompileResult.Instance;
}
else
{
shouldSucceed = true;
diagnostics.Add(new CSDiagnostic(new CSDiagnosticInfo(ErrorCode.ERR_NoTypeDef, "MissingType", missingIdentity), Location.None));
return null;
}
},
(AssemblyIdentity assemblyIdentity, out uint uSize) =>
{
uSize = (uint)missingModule.MetadataLength;
return missingModule.MetadataAddress;
},
out errorMessage);
Assert.Same(TestCompileResult.Instance, compileResult);
Assert.Null(errorMessage);
}
private sealed class TestCompileResult : CompileResult
{
public static readonly CompileResult Instance = new TestCompileResult();
private TestCompileResult()
: base(null, null, null, null)
{
}
public override CustomTypeInfo GetCustomTypeInfo()
{
throw new NotImplementedException();
}
}
private EvaluationContext CreateMethodContextWithReferences(Compilation comp, string methodName, params MetadataReference[] references)
{
......
......@@ -21,39 +21,6 @@ internal abstract class EvaluationContextBase
internal static readonly AssemblyIdentity SystemXmlLinqIdentity = new AssemblyIdentity("System.Xml.Linq");
internal static readonly AssemblyIdentity MicrosoftVisualBasicIdentity = new AssemblyIdentity("Microsoft.VisualBasic");
/// <summary>
/// Compile C# expression and emit assembly with evaluation method.
/// </summary>
/// <returns>
/// Result containing generated assembly, type and method names, and any format specifiers.
/// </returns>
internal CompileResult CompileExpression(
InspectionContext inspectionContext,
string expr,
DkmEvaluationFlags compilationFlags,
DiagnosticFormatter formatter,
out ResultProperties resultProperties,
out string error,
out ImmutableArray<AssemblyIdentity> missingAssemblyIdentities,
CultureInfo preferredUICulture,
CompilationTestData testData)
{
var diagnostics = DiagnosticBag.GetInstance();
var result = this.CompileExpression(inspectionContext, expr, compilationFlags, diagnostics, out resultProperties, testData);
if (diagnostics.HasAnyErrors())
{
bool useReferencedModulesOnly;
error = GetErrorMessageAndMissingAssemblyIdentities(diagnostics, formatter, preferredUICulture, out useReferencedModulesOnly, out missingAssemblyIdentities);
}
else
{
error = null;
missingAssemblyIdentities = ImmutableArray<AssemblyIdentity>.Empty;
}
diagnostics.Free();
return result;
}
internal abstract CompileResult CompileExpression(
InspectionContext inspectionContext,
string expr,
......
......@@ -292,13 +292,14 @@ private EvaluationContextBase CreateMethodContext(DkmClrInstructionAddress instr
DkmUtilities.GetMetadataBytesPtrFunction getMetaDataBytesPtr,
out string errorMessage)
{
errorMessage = null;
TResult compileResult;
PooledHashSet<AssemblyIdentity> assembliesLoadedInRetryLoop = null;
bool tryAgain;
do
{
errorMessage = null;
var context = createContext(metadataBlocks, useReferencedModulesOnly: false);
var diagnostics = DiagnosticBag.GetInstance();
compileResult = compile(context, diagnostics);
......
......@@ -106,6 +106,40 @@ internal static class ExpressionCompilerTestHelpers
return result;
}
/// <summary>
/// Compile C# expression and emit assembly with evaluation method.
/// </summary>
/// <returns>
/// Result containing generated assembly, type and method names, and any format specifiers.
/// </returns>
static internal CompileResult CompileExpression(
this EvaluationContextBase evaluationContext,
InspectionContext inspectionContext,
string expr,
DkmEvaluationFlags compilationFlags,
DiagnosticFormatter formatter,
out ResultProperties resultProperties,
out string error,
out ImmutableArray<AssemblyIdentity> missingAssemblyIdentities,
CultureInfo preferredUICulture,
CompilationTestData testData)
{
var diagnostics = DiagnosticBag.GetInstance();
var result = evaluationContext.CompileExpression(inspectionContext, expr, compilationFlags, diagnostics, out resultProperties, testData);
if (diagnostics.HasAnyErrors())
{
bool useReferencedModulesOnly;
error = evaluationContext.GetErrorMessageAndMissingAssemblyIdentities(diagnostics, formatter, preferredUICulture, out useReferencedModulesOnly, out missingAssemblyIdentities);
}
else
{
error = null;
missingAssemblyIdentities = ImmutableArray<AssemblyIdentity>.Empty;
}
diagnostics.Free();
return result;
}
internal static CompileResult CompileExpressionWithRetry(
ImmutableArray<MetadataBlock> metadataBlocks,
EvaluationContextBase context,
......
......@@ -121,7 +121,8 @@ internal static class FormattingRangeHelper
(parent is DelegateDeclarationSyntax) ||
(parent is FieldDeclarationSyntax) ||
(parent is EventFieldDeclarationSyntax) ||
(parent is MethodDeclarationSyntax))
(parent is MethodDeclarationSyntax) ||
(parent is PropertyDeclarationSyntax))
{
return ValueTuple.Create(GetAppropriatePreviousToken(parent.GetFirstToken(), canTokenBeFirstInABlock: true), parent.GetLastToken());
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册