diff --git a/src/Compilers/CSharp/Portable/Lowering/LambdaRewriter/LambdaCapturedVariable.cs b/src/Compilers/CSharp/Portable/Lowering/LambdaRewriter/LambdaCapturedVariable.cs index 57c0c119b55c1e742123316cdb069c8fafee521c..6681faa17c39887d2838fec3c777e8ef42359226 100644 --- a/src/Compilers/CSharp/Portable/Lowering/LambdaRewriter/LambdaCapturedVariable.cs +++ b/src/Compilers/CSharp/Portable/Lowering/LambdaRewriter/LambdaCapturedVariable.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Diagnostics; -using Microsoft.CodeAnalysis.CodeGen; using Microsoft.CodeAnalysis.CSharp.Symbols; using Roslyn.Utilities; @@ -98,5 +98,13 @@ internal override bool IsCapturedFrame return _isThis; } } + + internal override bool SuppressDynamicAttribute + { + get + { + return false; + } + } } } diff --git a/src/Compilers/CSharp/Portable/Lowering/StateMachineRewriter/StateMachineFieldSymbol.cs b/src/Compilers/CSharp/Portable/Lowering/StateMachineRewriter/StateMachineFieldSymbol.cs index 958c1eb3b7edd0784ecb85a400a255182234d6c4..d1dcf963d88997e96c5994e6af004417b9900d3c 100644 --- a/src/Compilers/CSharp/Portable/Lowering/StateMachineRewriter/StateMachineFieldSymbol.cs +++ b/src/Compilers/CSharp/Portable/Lowering/StateMachineRewriter/StateMachineFieldSymbol.cs @@ -42,6 +42,11 @@ public StateMachineFieldSymbol(NamedTypeSymbol stateMachineType, TypeSymbol type this.SlotDebugInfo = slotDebugInfo; } + internal override bool SuppressDynamicAttribute + { + get { return true; } + } + internal override TypeSymbol GetFieldType(ConsList fieldsBeingBound) { return _type; diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedBackingFieldSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedBackingFieldSymbol.cs index 4eee6e8b0625aef7d6d6126ada36736906e70170..10ce338ecdb26b4062b04e93abff1600d977aa62 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedBackingFieldSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedBackingFieldSymbol.cs @@ -2,10 +2,6 @@ using System.Collections.Immutable; using System.Diagnostics; -using Microsoft.CodeAnalysis.CSharp.Emit; -using Microsoft.CodeAnalysis.CSharp.Symbols; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using Microsoft.CodeAnalysis.Text; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.CSharp.Symbols @@ -53,6 +49,14 @@ public override ImmutableArray Locations } } + internal override bool SuppressDynamicAttribute + { + get + { + return false; + } + } + internal override TypeSymbol GetFieldType(ConsList fieldsBeingBound) { return _property.Type; diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedEnumValueFieldSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedEnumValueFieldSymbol.cs index 7a1c5cbd882cc80e96b8d5fdebe2a3e3dc601079..cbd19c31f3d36024895eadc934270ce681d6690b 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedEnumValueFieldSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedEnumValueFieldSymbol.cs @@ -1,6 +1,5 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.CodeAnalysis.CSharp.Emit; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.CSharp.Symbols @@ -15,6 +14,11 @@ public SynthesizedEnumValueFieldSymbol(SourceNamedTypeSymbol containingEnum) { } + internal override bool SuppressDynamicAttribute + { + get { return true; } + } + internal override TypeSymbol GetFieldType(ConsList fieldsBeingBound) { return ((SourceNamedTypeSymbol)ContainingType).EnumUnderlyingType; diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedFieldSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedFieldSymbol.cs index 8d03f1bf71143a2cf50c3b1179c0797b04cb8df6..80fb1361d2c4a6450d0c9c62e43ff6cdb2b19b40 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedFieldSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedFieldSymbol.cs @@ -11,7 +11,7 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols /// /// Represents a compiler generated field of given type and name. /// - internal class SynthesizedFieldSymbol : SynthesizedFieldSymbolBase + internal sealed class SynthesizedFieldSymbol : SynthesizedFieldSymbolBase { private readonly TypeSymbol _type; @@ -28,6 +28,11 @@ internal class SynthesizedFieldSymbol : SynthesizedFieldSymbolBase _type = type; } + internal override bool SuppressDynamicAttribute + { + get { return true; } + } + internal override TypeSymbol GetFieldType(ConsList fieldsBeingBound) { return _type; diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedFieldSymbolBase.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedFieldSymbolBase.cs index 9bb5b41e3aebda85e23d6c75df31d1418124a624..310b28a9547cff196d2aaaeb875d9b67c213d7c7 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedFieldSymbolBase.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedFieldSymbolBase.cs @@ -2,13 +2,12 @@ using System.Collections.Immutable; using System.Diagnostics; -using Microsoft.CodeAnalysis.CSharp.Emit; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.CSharp.Symbols { /// - /// Represents a compiler generated field. + /// Represents a compiler generated field or captured variable. /// internal abstract class SynthesizedFieldSymbolBase : FieldSymbol { @@ -33,21 +32,27 @@ internal abstract class SynthesizedFieldSymbolBase : FieldSymbol (isStatic ? DeclarationModifiers.Static : DeclarationModifiers.None); } + internal abstract bool SuppressDynamicAttribute + { + get; + } + internal override void AddSynthesizedAttributes(ModuleCompilationState compilationState, ref ArrayBuilder attributes) { base.AddSynthesizedAttributes(compilationState, ref attributes); - // do not emit Dynamic or CompilerGenerated attributes for fields inside compiler generated types: - if (_containingType.IsImplicitlyDeclared) - { - return; - } - CSharpCompilation compilation = this.DeclaringCompilation; - AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute(WellKnownMember.System_Runtime_CompilerServices_CompilerGeneratedAttribute__ctor)); + // do not emit CompilerGenerated attributes for fields inside compiler generated types: + if (!_containingType.IsImplicitlyDeclared) + { + AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute(WellKnownMember.System_Runtime_CompilerServices_CompilerGeneratedAttribute__ctor)); + } - if (this.Type.ContainsDynamic() && compilation.HasDynamicEmitAttributes() && compilation.CanEmitBoolean()) + if (!this.SuppressDynamicAttribute && + this.Type.ContainsDynamic() && + compilation.HasDynamicEmitAttributes() && + compilation.CanEmitBoolean()) { AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDynamicAttribute(this.Type, this.CustomModifiers.Length)); } diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedLambdaCacheFieldSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedLambdaCacheFieldSymbol.cs index ffbc7426a65308e4206027bde3f1fcff513c48bb..162808263a3b3002ceac49c62353e506c21ad22a 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedLambdaCacheFieldSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedLambdaCacheFieldSymbol.cs @@ -1,24 +1,35 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Diagnostics; +using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.CSharp.Symbols { - internal sealed class SynthesizedLambdaCacheFieldSymbol : SynthesizedFieldSymbol, ISynthesizedMethodBodyImplementationSymbol + internal sealed class SynthesizedLambdaCacheFieldSymbol : SynthesizedFieldSymbolBase, ISynthesizedMethodBodyImplementationSymbol { + private readonly TypeSymbol _type; private readonly MethodSymbol _topLevelMethod; public SynthesizedLambdaCacheFieldSymbol(NamedTypeSymbol containingType, TypeSymbol type, string name, MethodSymbol topLevelMethod, bool isReadOnly, bool isStatic) - : base(containingType, type, name, isPublic: true, isReadOnly: isReadOnly, isStatic: isStatic) + : base(containingType, name, isPublic: true, isReadOnly: isReadOnly, isStatic: isStatic) { - Debug.Assert(topLevelMethod != null); + Debug.Assert((object)type != null); + Debug.Assert((object)topLevelMethod != null); + _type = type; _topLevelMethod = topLevelMethod; } + internal override bool SuppressDynamicAttribute => true; + IMethodSymbol ISynthesizedMethodBodyImplementationSymbol.Method => _topLevelMethod; // When the containing top-level method body is updated we don't need to attempt to update the cache field // since a field update is a no-op. bool ISynthesizedMethodBodyImplementationSymbol.HasMethodBodyDependency => false; + + internal override TypeSymbol GetFieldType(ConsList fieldsBeingBound) + { + return _type; + } } } diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Dynamic.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Dynamic.cs index 5c95b0ad89bf44054cf10c05efc38da016cec8db..aa5f7b929e4c39908b2350e90aaf6d4496277732 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Dynamic.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Dynamic.cs @@ -1264,5 +1264,94 @@ static void Main() // Make sure we emit without errors when System.Boolean is missing. CompileAndVerify(comp, verify: false); } + + [Fact] + [WorkItem(7840, "https://github.com/dotnet/roslyn/issues/7840")] + public void DynamicDisplayClassFieldMissingBoolean() + { + var source0 = +@"namespace System +{ + public class Object { } + public struct Int32 { } + public class ValueType { } + public class Attribute { } + public struct Void { } + public struct IntPtr { } + public class MulticastDelegate { } +}"; + var source1 = +@"delegate void D(); +class C +{ + static void Main() + { + dynamic x = 1; + D d = () => { dynamic y = x; }; + } +}"; + var comp = CreateCompilation(source0); + comp.VerifyDiagnostics(); + var ref0 = comp.EmitToImageReference(); + comp = CreateCompilation(source1, references: new[] { ref0, SystemCoreRef }); + comp.VerifyDiagnostics(); + // Make sure we emit without errors when System.Boolean is missing. + CompileAndVerify(comp, verify: false); + } + + [Fact] + public void BackingField() + { + var source = +@"class C +{ + static dynamic[] P { get; set; } +}"; + CompileAndVerify(source, additionalRefs: new[] { CSharpRef, SystemCoreRef }, expectedSignatures: new[] + { + Signature( + "C", + "

k__BackingField", + ".field [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [System.Runtime.CompilerServices.DynamicAttribute(System.Collections.ObjectModel.ReadOnlyCollection`1[System.Reflection.CustomAttributeTypedArgument])] private static System.Object[]

k__BackingField") + }); + } + + [Fact] + [WorkItem(1095613, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1095613")] + public void DisplayClassField() + { + var source = +@"using System; +class C +{ + static void F(dynamic[] a) + { + H(() => G(a)); + dynamic d = a; + H(() => G(d)); + } + static void G(object a) + { + } + static void H(Action a) + { + } + static void Main() + { + F(new object[0]); + } +}"; + CompileAndVerify(source, additionalRefs: new[] { CSharpRef, SystemCoreRef }, expectedSignatures: new[] + { + Signature( + "C+<>c__DisplayClass0_0", + "a", + ".field [System.Runtime.CompilerServices.DynamicAttribute(System.Collections.ObjectModel.ReadOnlyCollection`1[System.Reflection.CustomAttributeTypedArgument])] public instance System.Object[] a"), + Signature( + "C+<>c__DisplayClass0_0", + "d", + ".field [System.Runtime.CompilerServices.DynamicAttribute()] public instance System.Object d") + }); + } } } diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDynamicTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDynamicTests.cs index c39b65fb5f17465dafe851137622c0de84fbb53e..77ca3c97753c648b2272397052fd16894a5aa5bc 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDynamicTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDynamicTests.cs @@ -55,6 +55,7 @@ public class CodeGen_DynamicTests : CSharpTestBase #endregion + #region C# Runtime and System.Core sources private const string CSharpBinderTemplate = @" @@ -545,7 +546,9 @@ public void M1(dynamic d) var displayClass = c.GetMember("<>c__DisplayClass0_0"); var d = displayClass.GetMember("d"); - Assert.Equal(0, d.GetAttributes().Length); + var attributes = d.GetAttributes(); + Assert.Equal(1, attributes.Length); + Assert.Equal("System.Runtime.CompilerServices.DynamicAttribute", attributes[0].AttributeClass.ToDisplayString()); }); } @@ -950,7 +953,7 @@ .maxstack 9 IL_0069: ldarg.0 IL_006a: ldfld ""T C.<>c__DisplayClass0_0.a"" IL_006f: ldarg.0 - IL_0070: ldfld ""object C.<>c__DisplayClass0_0.b"" + IL_0070: ldfld """" IL_0075: callvirt ""void System.Action.Invoke(System.Runtime.CompilerServices.CallSite, System.Type, T, object)"" IL_007a: ret } @@ -1033,7 +1036,7 @@ .maxstack 13 IL_0005: stloc.0 IL_0006: ldloc.0 IL_0007: newobj ""C..ctor()"" - IL_000c: stfld ""object C.<>c__DisplayClass11_0.dyn"" + IL_000c: stfld ""dynamic C.<>c__DisplayClass11_0.dyn"" IL_0011: ldsfld ""System.Runtime.CompilerServices.CallSite> C.<>o__11.<>p__2"" IL_0016: brtrue.s IL_0044 IL_0018: ldc.i4.0 @@ -1101,7 +1104,7 @@ .maxstack 13 IL_00da: ldfld ""System.Func System.Runtime.CompilerServices.CallSite>.Target"" IL_00df: ldsfld ""System.Runtime.CompilerServices.CallSite> C.<>o__11.<>p__0"" IL_00e4: ldloc.0 - IL_00e5: ldfld ""object C.<>c__DisplayClass11_0.dyn"" + IL_00e5: ldfld ""dynamic C.<>c__DisplayClass11_0.dyn"" IL_00ea: callvirt ""object System.Func.Invoke(System.Runtime.CompilerServices.CallSite, object)"" IL_00ef: ldc.i4.s 123 IL_00f1: callvirt ""object System.Func.Invoke(System.Runtime.CompilerServices.CallSite, object, int)"" @@ -1137,7 +1140,7 @@ .maxstack 13 IL_014d: ldfld ""System.Func System.Runtime.CompilerServices.CallSite>.Target"" IL_0152: ldsfld ""System.Runtime.CompilerServices.CallSite> C.<>o__11.<>p__4"" IL_0157: ldloc.0 - IL_0158: ldfld ""object C.<>c__DisplayClass11_0.dyn"" + IL_0158: ldfld ""dynamic C.<>c__DisplayClass11_0.dyn"" IL_015d: ldsfld ""System.Runtime.CompilerServices.CallSite> C.<>o__11.<>p__3"" IL_0162: brtrue.s IL_019e IL_0164: ldc.i4.0 @@ -1166,7 +1169,7 @@ .maxstack 13 IL_01a3: ldfld ""System.Func System.Runtime.CompilerServices.CallSite>.Target"" IL_01a8: ldsfld ""System.Runtime.CompilerServices.CallSite> C.<>o__11.<>p__3"" IL_01ad: ldloc.0 - IL_01ae: ldfld ""object C.<>c__DisplayClass11_0.dyn"" + IL_01ae: ldfld ""dynamic C.<>c__DisplayClass11_0.dyn"" IL_01b3: ldloc.1 IL_01b4: callvirt ""object System.Func.Invoke(System.Runtime.CompilerServices.CallSite, object, object)"" IL_01b9: callvirt ""object System.Func.Invoke(System.Runtime.CompilerServices.CallSite, object, object)"" @@ -1198,7 +1201,7 @@ .maxstack 13 IL_0204: ldfld ""System.Func System.Runtime.CompilerServices.CallSite>.Target"" IL_0209: ldsfld ""System.Runtime.CompilerServices.CallSite> C.<>o__11.<>p__7"" IL_020e: ldloc.0 - IL_020f: ldfld ""object C.<>c__DisplayClass11_0.dyn"" + IL_020f: ldfld ""dynamic C.<>c__DisplayClass11_0.dyn"" IL_0214: ldsfld ""System.Runtime.CompilerServices.CallSite> C.<>o__11.<>p__6"" IL_0219: brtrue.s IL_024b IL_021b: ldc.i4.0 @@ -1241,7 +1244,7 @@ .maxstack 13 IL_0295: ldfld ""System.Func System.Runtime.CompilerServices.CallSite>.Target"" IL_029a: ldsfld ""System.Runtime.CompilerServices.CallSite> C.<>o__11.<>p__5"" IL_029f: ldloc.0 - IL_02a0: ldfld ""object C.<>c__DisplayClass11_0.dyn"" + IL_02a0: ldfld ""dynamic C.<>c__DisplayClass11_0.dyn"" IL_02a5: callvirt ""object System.Func.Invoke(System.Runtime.CompilerServices.CallSite, object)"" IL_02aa: callvirt ""object System.Func.Invoke(System.Runtime.CompilerServices.CallSite, object)"" IL_02af: callvirt ""object System.Func.Invoke(System.Runtime.CompilerServices.CallSite, object, object)"" @@ -1251,7 +1254,7 @@ .maxstack 13 IL_02bc: newobj ""System.Action..ctor(object, System.IntPtr)"" IL_02c1: stloc.2 IL_02c2: ldloc.0 - IL_02c3: ldfld ""object C.<>c__DisplayClass11_0.dyn"" + IL_02c3: ldfld ""dynamic C.<>c__DisplayClass11_0.dyn"" IL_02c8: stloc.3 IL_02c9: ldsfld ""System.Runtime.CompilerServices.CallSite> C.<>o__11.<>p__14"" IL_02ce: brtrue.s IL_02ef @@ -8763,11 +8766,10 @@ .maxstack 9 IL_0055: ldtoken ""C"" IL_005a: call ""System.Type System.Type.GetTypeFromHandle(System.RuntimeTypeHandle)"" IL_005f: ldarg.0 - IL_0060: ldfld ""object C.<>c__DisplayClass0_0.x"" + IL_0060: ldfld ""dynamic C.<>c__DisplayClass0_0.x"" IL_0065: callvirt ""void System.Action.Invoke(System.Runtime.CompilerServices.CallSite, System.Type, object)"" IL_006a: ret -} -"); +}"); } [Fact] @@ -14483,7 +14485,7 @@ .maxstack 10 IL_008e: ldsfld ""System.Runtime.CompilerServices.CallSite> C.<>o__0.<>p__0"" IL_0093: ldarg.0 IL_0094: ldfld ""C.<>c__DisplayClass0_0 C.<>c__DisplayClass0_0.<

b__0>d.<>4__this"" - IL_0099: ldfld ""object C.<>c__DisplayClass0_0.d"" + IL_0099: ldfld ""dynamic C.<>c__DisplayClass0_0.d"" IL_009e: callvirt ""object System.Func.Invoke(System.Runtime.CompilerServices.CallSite, object)"" IL_00a3: callvirt ""object System.Func.Invoke(System.Runtime.CompilerServices.CallSite, object)"" IL_00a8: stloc.2 diff --git a/src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/DynamicTests.cs b/src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/DynamicTests.cs index 56f6bbc154af476254a8b9ab5dbdddc3720a015e..7855d940929e39b7249cf742e28c560f15dab47e 100644 --- a/src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/DynamicTests.cs +++ b/src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/DynamicTests.cs @@ -1329,7 +1329,7 @@ .maxstack 9 } [WorkItem(1095613, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1095613")] - [Fact(Skip = "1095613")] + [Fact] public void HoistedLocalsLoseDynamicAttribute() { var source = @" @@ -1356,114 +1356,89 @@ static void Foo(int x) var result = context.CompileExpression("Foo(x)", out error, testData); Assert.Null(error); VerifyCustomTypeInfo(result, 0x01); - testData.GetMethodData("<>c.<>m0()").VerifyIL(@" -{ - // Code size 166 (0xa6) - .maxstack 11 - .locals init (System.Func V_0) //a - IL_0000: ldsfld ""System.Runtime.CompilerServices.CallSite>> <>c.<<>m0>o__SiteContainer0.<>p__Site2"" - IL_0005: brtrue.s IL_002b + testData.GetMethodData("<>x.<>m0").VerifyIL( +@"{ + // Code size 103 (0x67) + .maxstack 9 + .locals init (C.<>c__DisplayClass0_0 V_0, //CS$<>8__locals0 + System.Func V_1) //a + IL_0000: ldsfld ""System.Runtime.CompilerServices.CallSite> <>x.<>o__0.<>p__0"" + IL_0005: brtrue.s IL_0042 IL_0007: ldc.i4.0 - IL_0008: ldtoken ""System.Func"" - IL_000d: call ""System.Type System.Type.GetTypeFromHandle(System.RuntimeTypeHandle)"" - IL_0012: ldtoken ""<>c"" - IL_0017: call ""System.Type System.Type.GetTypeFromHandle(System.RuntimeTypeHandle)"" - IL_001c: call ""System.Runtime.CompilerServices.CallSiteBinder Microsoft.CSharp.RuntimeBinder.Binder.Convert(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags, System.Type, System.Type)"" - IL_0021: call ""System.Runtime.CompilerServices.CallSite>> System.Runtime.CompilerServices.CallSite>>.Create(System.Runtime.CompilerServices.CallSiteBinder)"" - IL_0026: stsfld ""System.Runtime.CompilerServices.CallSite>> <>c.<<>m0>o__SiteContainer0.<>p__Site2"" - IL_002b: ldsfld ""System.Runtime.CompilerServices.CallSite>> <>c.<<>m0>o__SiteContainer0.<>p__Site2"" - IL_0030: ldfld ""System.Func> System.Runtime.CompilerServices.CallSite>>.Target"" - IL_0035: ldsfld ""System.Runtime.CompilerServices.CallSite>> <>c.<<>m0>o__SiteContainer0.<>p__Site2"" - IL_003a: ldsfld ""System.Runtime.CompilerServices.CallSite> <>c.<<>m0>o__SiteContainer0.<>p__Site1"" - IL_003f: brtrue.s IL_007c - IL_0041: ldc.i4.0 - IL_0042: ldstr ""Foo"" - IL_0047: ldnull - IL_0048: ldtoken ""<>c"" - IL_004d: call ""System.Type System.Type.GetTypeFromHandle(System.RuntimeTypeHandle)"" - IL_0052: ldc.i4.2 - IL_0053: newarr ""Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo"" - IL_0058: dup - IL_0059: ldc.i4.0 - IL_005a: ldc.i4.s 33 - IL_005c: ldnull - IL_005d: call ""Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create(Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags, string)"" - IL_0062: stelem.ref - IL_0063: dup - IL_0064: ldc.i4.1 - IL_0065: ldc.i4.0 - IL_0066: ldnull - IL_0067: call ""Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create(Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags, string)"" - IL_006c: stelem.ref - IL_006d: call ""System.Runtime.CompilerServices.CallSiteBinder Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags, string, System.Collections.Generic.IEnumerable, System.Type, System.Collections.Generic.IEnumerable)"" - IL_0072: call ""System.Runtime.CompilerServices.CallSite> System.Runtime.CompilerServices.CallSite>.Create(System.Runtime.CompilerServices.CallSiteBinder)"" - IL_0077: stsfld ""System.Runtime.CompilerServices.CallSite> <>c.<<>m0>o__SiteContainer0.<>p__Site1"" - IL_007c: ldsfld ""System.Runtime.CompilerServices.CallSite> <>c.<<>m0>o__SiteContainer0.<>p__Site1"" - IL_0081: ldfld ""System.Func System.Runtime.CompilerServices.CallSite>.Target"" - IL_0086: ldsfld ""System.Runtime.CompilerServices.CallSite> <>c.<<>m0>o__SiteContainer0.<>p__Site1"" - IL_008b: ldtoken ""<>c"" - IL_0090: call ""System.Type System.Type.GetTypeFromHandle(System.RuntimeTypeHandle)"" - IL_0095: ldsfld ""dynamic C.x"" - IL_009a: callvirt ""dynamic System.Func.Invoke(System.Runtime.CompilerServices.CallSite, System.Type, dynamic)"" - IL_009f: callvirt ""System.Func System.Func>.Invoke(System.Runtime.CompilerServices.CallSite, dynamic)"" - IL_00a4: stloc.0 - IL_00a5: ret + IL_0008: ldstr ""Foo"" + IL_000d: ldnull + IL_000e: ldtoken ""C"" + IL_0013: call ""System.Type System.Type.GetTypeFromHandle(System.RuntimeTypeHandle)"" + IL_0018: ldc.i4.2 + IL_0019: newarr ""Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo"" + IL_001e: dup + IL_001f: ldc.i4.0 + IL_0020: ldc.i4.s 33 + IL_0022: ldnull + IL_0023: call ""Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create(Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags, string)"" + IL_0028: stelem.ref + IL_0029: dup + IL_002a: ldc.i4.1 + IL_002b: ldc.i4.0 + IL_002c: ldnull + IL_002d: call ""Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create(Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags, string)"" + IL_0032: stelem.ref + IL_0033: call ""System.Runtime.CompilerServices.CallSiteBinder Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags, string, System.Collections.Generic.IEnumerable, System.Type, System.Collections.Generic.IEnumerable)"" + IL_0038: call ""System.Runtime.CompilerServices.CallSite> System.Runtime.CompilerServices.CallSite>.Create(System.Runtime.CompilerServices.CallSiteBinder)"" + IL_003d: stsfld ""System.Runtime.CompilerServices.CallSite> <>x.<>o__0.<>p__0"" + IL_0042: ldsfld ""System.Runtime.CompilerServices.CallSite> <>x.<>o__0.<>p__0"" + IL_0047: ldfld ""System.Func System.Runtime.CompilerServices.CallSite>.Target"" + IL_004c: ldsfld ""System.Runtime.CompilerServices.CallSite> <>x.<>o__0.<>p__0"" + IL_0051: ldtoken ""<>x"" + IL_0056: call ""System.Type System.Type.GetTypeFromHandle(System.RuntimeTypeHandle)"" + IL_005b: ldloc.0 + IL_005c: ldfld ""dynamic C.<>c__DisplayClass0_0.x"" + IL_0061: callvirt ""dynamic System.Func.Invoke(System.Runtime.CompilerServices.CallSite, System.Type, dynamic)"" + IL_0066: ret }"); + testData = new CompilationTestData(); result = context.CompileExpression("Foo(y)", out error, testData); Assert.Null(error); VerifyCustomTypeInfo(result, 0x01); - testData.GetMethodData("<>c.<>m0()").VerifyIL(@" -{ - // Code size 166 (0xa6) - .maxstack 11 - .locals init (System.Func V_0) //a - IL_0000: ldsfld ""System.Runtime.CompilerServices.CallSite>> <>c.<<>m0>o__SiteContainer0.<>p__Site2"" - IL_0005: brtrue.s IL_002b + testData.GetMethodData("<>x.<>m0").VerifyIL( +@"{ + // Code size 103 (0x67) + .maxstack 9 + .locals init (C.<>c__DisplayClass0_0 V_0, //CS$<>8__locals0 + System.Func V_1) //a + IL_0000: ldsfld ""System.Runtime.CompilerServices.CallSite> <>x.<>o__0.<>p__0"" + IL_0005: brtrue.s IL_0042 IL_0007: ldc.i4.0 - IL_0008: ldtoken ""System.Func"" - IL_000d: call ""System.Type System.Type.GetTypeFromHandle(System.RuntimeTypeHandle)"" - IL_0012: ldtoken ""<>c"" - IL_0017: call ""System.Type System.Type.GetTypeFromHandle(System.RuntimeTypeHandle)"" - IL_001c: call ""System.Runtime.CompilerServices.CallSiteBinder Microsoft.CSharp.RuntimeBinder.Binder.Convert(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags, System.Type, System.Type)"" - IL_0021: call ""System.Runtime.CompilerServices.CallSite>> System.Runtime.CompilerServices.CallSite>>.Create(System.Runtime.CompilerServices.CallSiteBinder)"" - IL_0026: stsfld ""System.Runtime.CompilerServices.CallSite>> <>c.<<>m0>o__SiteContainer0.<>p__Site2"" - IL_002b: ldsfld ""System.Runtime.CompilerServices.CallSite>> <>c.<<>m0>o__SiteContainer0.<>p__Site2"" - IL_0030: ldfld ""System.Func> System.Runtime.CompilerServices.CallSite>>.Target"" - IL_0035: ldsfld ""System.Runtime.CompilerServices.CallSite>> <>c.<<>m0>o__SiteContainer0.<>p__Site2"" - IL_003a: ldsfld ""System.Runtime.CompilerServices.CallSite> <>c.<<>m0>o__SiteContainer0.<>p__Site1"" - IL_003f: brtrue.s IL_007c - IL_0041: ldc.i4.0 - IL_0042: ldstr ""Foo"" - IL_0047: ldnull - IL_0048: ldtoken ""<>c"" - IL_004d: call ""System.Type System.Type.GetTypeFromHandle(System.RuntimeTypeHandle)"" - IL_0052: ldc.i4.2 - IL_0053: newarr ""Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo"" - IL_0058: dup - IL_0059: ldc.i4.0 - IL_005a: ldc.i4.s 33 - IL_005c: ldnull - IL_005d: call ""Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create(Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags, string)"" - IL_0062: stelem.ref - IL_0063: dup - IL_0064: ldc.i4.1 - IL_0065: ldc.i4.0 - IL_0066: ldnull - IL_0067: call ""Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create(Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags, string)"" - IL_006c: stelem.ref - IL_006d: call ""System.Runtime.CompilerServices.CallSiteBinder Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags, string, System.Collections.Generic.IEnumerable, System.Type, System.Collections.Generic.IEnumerable)"" - IL_0072: call ""System.Runtime.CompilerServices.CallSite> System.Runtime.CompilerServices.CallSite>.Create(System.Runtime.CompilerServices.CallSiteBinder)"" - IL_0077: stsfld ""System.Runtime.CompilerServices.CallSite> <>c.<<>m0>o__SiteContainer0.<>p__Site1"" - IL_007c: ldsfld ""System.Runtime.CompilerServices.CallSite> <>c.<<>m0>o__SiteContainer0.<>p__Site1"" - IL_0081: ldfld ""System.Func System.Runtime.CompilerServices.CallSite>.Target"" - IL_0086: ldsfld ""System.Runtime.CompilerServices.CallSite> <>c.<<>m0>o__SiteContainer0.<>p__Site1"" - IL_008b: ldtoken ""<>c"" - IL_0090: call ""System.Type System.Type.GetTypeFromHandle(System.RuntimeTypeHandle)"" - IL_0095: ldsfld ""dynamic C.x"" - IL_009a: callvirt ""dynamic System.Func.Invoke(System.Runtime.CompilerServices.CallSite, System.Type, dynamic)"" - IL_009f: callvirt ""System.Func System.Func>.Invoke(System.Runtime.CompilerServices.CallSite, dynamic)"" - IL_00a4: stloc.0 - IL_00a5: ret + IL_0008: ldstr ""Foo"" + IL_000d: ldnull + IL_000e: ldtoken ""C"" + IL_0013: call ""System.Type System.Type.GetTypeFromHandle(System.RuntimeTypeHandle)"" + IL_0018: ldc.i4.2 + IL_0019: newarr ""Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo"" + IL_001e: dup + IL_001f: ldc.i4.0 + IL_0020: ldc.i4.s 33 + IL_0022: ldnull + IL_0023: call ""Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create(Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags, string)"" + IL_0028: stelem.ref + IL_0029: dup + IL_002a: ldc.i4.1 + IL_002b: ldc.i4.0 + IL_002c: ldnull + IL_002d: call ""Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create(Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfoFlags, string)"" + IL_0032: stelem.ref + IL_0033: call ""System.Runtime.CompilerServices.CallSiteBinder Microsoft.CSharp.RuntimeBinder.Binder.InvokeMember(Microsoft.CSharp.RuntimeBinder.CSharpBinderFlags, string, System.Collections.Generic.IEnumerable, System.Type, System.Collections.Generic.IEnumerable)"" + IL_0038: call ""System.Runtime.CompilerServices.CallSite> System.Runtime.CompilerServices.CallSite>.Create(System.Runtime.CompilerServices.CallSiteBinder)"" + IL_003d: stsfld ""System.Runtime.CompilerServices.CallSite> <>x.<>o__0.<>p__0"" + IL_0042: ldsfld ""System.Runtime.CompilerServices.CallSite> <>x.<>o__0.<>p__0"" + IL_0047: ldfld ""System.Func System.Runtime.CompilerServices.CallSite>.Target"" + IL_004c: ldsfld ""System.Runtime.CompilerServices.CallSite> <>x.<>o__0.<>p__0"" + IL_0051: ldtoken ""<>x"" + IL_0056: call ""System.Type System.Type.GetTypeFromHandle(System.RuntimeTypeHandle)"" + IL_005b: ldloc.0 + IL_005c: ldfld ""dynamic C.<>c__DisplayClass0_0.y"" + IL_0061: callvirt ""dynamic System.Func.Invoke(System.Runtime.CompilerServices.CallSite, System.Type, dynamic)"" + IL_0066: ret }"); }); }