public AsyncStruct(MethodSymbol method) : base(method, GeneratedNames.MakeIteratorOrAsyncDisplayClassName(method.Name, SequenceNumber(method)), TypeKind.Struct) { // TODO: report use-site errors on these types this.interfaces = ImmutableArray.Create <NamedTypeSymbol>(method.DeclaringCompilation.GetWellKnownType(WellKnownType.System_Runtime_CompilerServices_IAsyncStateMachine)); this.constructor = new SynthesizedInstanceConstructor(this); }
public AsyncStruct(MethodSymbol method, TypeCompilationState compilationState) : base(method, GeneratedNames.MakeIteratorOrAsyncDisplayClassName(method.Name, compilationState.GenerateTempNumber()), TypeKind.Struct) { this.interfaces = ReadOnlyArray <NamedTypeSymbol> .CreateFrom( compilationState.EmitModule.Compilation.GetWellKnownType(WellKnownType.System_Runtime_CompilerServices_IAsyncStateMachine)); this.constructor = new SynthesizedInstanceConstructor(this); }
public AsyncStateMachine(MethodSymbol asyncMethod, TypeKind typeKind) : base(GeneratedNames.MakeIteratorOrAsyncDisplayClassName(asyncMethod.Name, SequenceNumber(asyncMethod)), asyncMethod) { // TODO: report use-site errors on these types this.typeKind = typeKind; this.asyncMethod = asyncMethod; this.interfaces = ImmutableArray.Create(asyncMethod.DeclaringCompilation.GetWellKnownType(WellKnownType.System_Runtime_CompilerServices_IAsyncStateMachine)); this.constructor = new AsyncConstructor(this); }
public void TestStateMachineMethods() { var sourceTemplate = @" using System.Collections.Generic; using System.Threading.Tasks; class Iterators {{ IEnumerable<int> {0}() {{ yield return 1; }} IEnumerable<int> {0}1() {{ yield return 1; }} }} class Async {{ async Task {0}() {{ await {0}(); }} async Task {0}1() {{ await {0}1(); }} }} "; int padding = GeneratedNames.MakeIteratorOrAsyncDisplayClassName("A", 1).Length - 1; string longName = LongSymbolName.Substring(padding); var source = string.Format(sourceTemplate, longName); var comp = CreateCompilationWithMscorlib45(source); comp.VerifyDiagnostics(); // CONSIDER: Location would light up if synthesized methods had them. comp.VerifyEmitDiagnostics( // error CS7013: Name '<longName1>d__1' exceeds the maximum length allowed in metadata. Diagnostic(ErrorCode.ERR_MetadataNameTooLong).WithArguments("<" + longName + 1 + ">d__1").WithLocation(1, 1), // error CS7013: Name '<longName1>d__1' exceeds the maximum length allowed in metadata. Diagnostic(ErrorCode.ERR_MetadataNameTooLong).WithArguments("<" + longName + 1 + ">d__1").WithLocation(1, 1)); }
public IteratorClass(MethodSymbol method, bool isEnumerable, TypeSymbol elementType, TypeCompilationState compilationState) : base(method, GeneratedNames.MakeIteratorOrAsyncDisplayClassName(method.Name, compilationState.GenerateTempNumber()), TypeKind.Class) { this.ElementType = TypeMap.SubstituteType(elementType); var interfaces = ArrayBuilder <NamedTypeSymbol> .GetInstance(); if (isEnumerable) { interfaces.Add(ContainingAssembly.GetSpecialType(SpecialType.System_Collections_Generic_IEnumerable_T).Construct(ElementType)); interfaces.Add(ContainingAssembly.GetSpecialType(SpecialType.System_Collections_IEnumerable)); } interfaces.Add(ContainingAssembly.GetSpecialType(SpecialType.System_Collections_Generic_IEnumerator_T).Construct(ElementType)); interfaces.Add(ContainingAssembly.GetSpecialType(SpecialType.System_IDisposable)); interfaces.Add(ContainingAssembly.GetSpecialType(SpecialType.System_Collections_IEnumerator)); this.interfaces = interfaces.ToImmutableAndFree(); this.constructor = new IteratorConstructor(this); }