提交 3ef42040 编写于 作者: J Julien

Merge pull request #9476 from jcouv/fix-9167

Fix for #9167: async and iterator rewriters do not require optional attribute types
......@@ -2326,5 +2326,73 @@ .maxstack 3
}");
Assert.True(expectedIL.IndexOf("<>_", StringComparison.Ordinal) < 0);
}
[Fact, WorkItem(9167, "https://github.com/dotnet/roslyn/issues/9167")]
public void IteratorShouldCompileWithoutOptionalAttributes()
{
#region IL for corlib without CompilerGeneratedAttribute or DebuggerNonUserCodeAttribute
var corlib = @"
namespace System
{
public class Object { }
public struct Int32 { }
public struct Boolean { }
public class String { }
public class Exception { }
public class NotSupportedException : Exception { }
public class ValueType { }
public class Enum { }
public struct Void { }
public interface IDisposable
{
void Dispose();
}
}
namespace System.Collections
{
public interface IEnumerable
{
IEnumerator GetEnumerator();
}
public interface IEnumerator
{
bool MoveNext();
object Current { get; }
void Reset();
}
namespace Generic
{
public interface IEnumerable<T> : IEnumerable
{
new IEnumerator<T> GetEnumerator();
}
public interface IEnumerator<T> : IEnumerator
{
new T Current { get; }
}
}
}";
#endregion
var source = @"
public class C
{
public System.Collections.IEnumerable SomeNumbers()
{
yield return 42;
}
}";
// The compilation succeeds even though CompilerGeneratedAttribute and DebuggerNonUserCodeAttribute are not available.
var compilation = CreateCompilation(new[] { Parse(source), Parse(corlib) });
var verifier = CompileAndVerify(compilation, verify: false);
verifier.VerifyDiagnostics(
// warning CS8021: No value for RuntimeMetadataVersion found. No assembly containing System.Object was found nor was a value for RuntimeMetadataVersion specified through options.
Diagnostic(ErrorCode.WRN_NoRuntimeMetadataVersion).WithLocation(1, 1));
}
}
}
......@@ -295,11 +295,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Friend Overrides Function EnsureAllSymbolsAndSignature() As Boolean
Dim hasErrors As Boolean = MyBase.EnsureAllSymbolsAndSignature
' NOTE: in current implementation these attributes must exist
' TODO: change to "don't use if not found"
EnsureWellKnownMember(Of MethodSymbol)(WellKnownMember.System_Runtime_CompilerServices_CompilerGeneratedAttribute__ctor, hasErrors)
EnsureWellKnownMember(Of MethodSymbol)(WellKnownMember.System_Diagnostics_DebuggerHiddenAttribute__ctor, hasErrors)
EnsureSpecialType(SpecialType.System_Object, hasErrors)
EnsureSpecialType(SpecialType.System_Void, hasErrors)
EnsureSpecialType(SpecialType.System_ValueType, hasErrors)
......
......@@ -86,11 +86,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
hasErrors = True
End If
' NOTE: in current implementation these attributes must exist
' TODO: change to "don't use if not found"
EnsureWellKnownMember(Of MethodSymbol)(WellKnownMember.System_Runtime_CompilerServices_CompilerGeneratedAttribute__ctor, hasErrors)
EnsureWellKnownMember(Of MethodSymbol)(WellKnownMember.System_Diagnostics_DebuggerNonUserCodeAttribute__ctor, hasErrors)
' NOTE: We don't ensure DebuggerStepThroughAttribute, it is just not emitted if not found
' EnsureWellKnownMember(Of MethodSymbol)(WellKnownMember.System_Diagnostics_DebuggerStepThroughAttribute__ctor, hasErrors)
......
......@@ -1618,5 +1618,75 @@ End Module
CompileAndVerify(source, expectedOutput:="420420")
End Sub
<Fact, WorkItem(9167, "https://github.com/dotnet/roslyn/issues/9167")>
Public Sub IteratorShouldCompileWithoutOptionalAttributes()
#Region "IL For corlib without CompilerGeneratedAttribute Or DebuggerNonUserCodeAttribute"
Dim corlib = "
Namespace System
Public Class [Object]
End Class
Public Class [Int32]
End Class
Public Class [Boolean]
End Class
Public Class [String]
End Class
Public Class Exception
End Class
Public Class NotSupportedException
Inherits Exception
End Class
Public Class ValueType
End Class
Public Class [Enum]
End Class
Public Class Void
End Class
Public Interface IDisposable
Sub Dispose()
End Interface
End Namespace
Namespace System.Collections
Public Interface IEnumerable
Function GetEnumerator() As IEnumerator
End Interface
Public Interface IEnumerator
Function MoveNext() As Boolean
Property Current As Object
Sub Reset()
End Interface
Namespace Generic
Public Interface IEnumerable(Of T)
Inherits IEnumerable
Overloads Function GetEnumerator() As IEnumerator(Of T)
End Interface
Public Interface IEnumerator(Of T)
Inherits IEnumerator
Overloads Property Current As T
End Interface
End Namespace
End Namespace
Namespace System.Threading
Public Class Thread
Shared Property CurrentThread As Thread
Property ManagedThreadId As Integer
End Class
End Namespace
"
#End Region
Dim source = "
Class C
Public Iterator Function SomeNumbers() As System.Collections.IEnumerable
Yield Nothing
End Function
End Class
"
' The compilation succeeds even though CompilerGeneratedAttribute and DebuggerNonUserCodeAttribute are not available.
Dim compilation = CompilationUtils.CreateCompilation({Parse(source), Parse(corlib)})
Dim verifier = CompileAndVerify(compilation, verify:=False)
verifier.VerifyDiagnostics()
End Sub
End Class
End Namespace
......@@ -4456,26 +4456,6 @@ End Class
Imports System
Imports System.Threading.Tasks
' TODO: the attribute shouldn't be needed (https://github.com/dotnet/roslyn/issues/9167)
Namespace System.Runtime.CompilerServices
<AttributeUsage(AttributeTargets.All)>
Public Class CompilerGeneratedAttribute
Inherits Attribute
Public Sub New()
End Sub
End Class
End Namespace
' TODO: the attribute shouldn't be needed (https://github.com/dotnet/roslyn/issues/9167)
Namespace System.Diagnostics
<AttributeUsage(AttributeTargets.All)>
Public Class DebuggerHiddenAttribute
Inherits Attribute
Public Sub New()
End Sub
End Class
End Namespace
Namespace Microsoft.VisualBasic.CompilerServices
Class ProjectData
Shared Sub SetProjectError(e As Exception)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册