public void SubmissionEntryPoint()
        {
            var references = new[] { MscorlibRef_v4_0_30316_17626, SystemCoreRef };
            var source0 =
@"{
    await System.Threading.Tasks.Task.Delay(100);
    System.Console.Write(""complete"");
}";
            var s0 = CSharpCompilation.CreateScriptCompilation(
                "s0.dll",
                SyntaxFactory.ParseSyntaxTree(source0, options: TestOptions.Script),
                references);
            var verifier = CompileAndVerify(s0, verify: false);
            var methodData = verifier.TestData.GetMethodData("<Initialize>");
            Assert.Equal("System.Threading.Tasks.Task<object>", methodData.Method.ReturnType.ToDisplayString());
            methodData.VerifyIL(
@"{
  // Code size       60 (0x3c)
  .maxstack  2
  .locals init (<<Initialize>>d__0 V_0,
                System.Runtime.CompilerServices.AsyncTaskMethodBuilder<object> V_1)
  IL_0000:  newobj     ""<<Initialize>>d__0..ctor()""
  IL_0005:  stloc.0
  IL_0006:  ldloc.0
  IL_0007:  ldarg.0
  IL_0008:  stfld      ""Script <<Initialize>>d__0.<>4__this""
  IL_000d:  ldloc.0
  IL_000e:  call       ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder<object> System.Runtime.CompilerServices.AsyncTaskMethodBuilder<object>.Create()""
  IL_0013:  stfld      ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder<object> <<Initialize>>d__0.<>t__builder""
  IL_0018:  ldloc.0
  IL_0019:  ldc.i4.m1
  IL_001a:  stfld      ""int <<Initialize>>d__0.<>1__state""
  IL_001f:  ldloc.0
  IL_0020:  ldfld      ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder<object> <<Initialize>>d__0.<>t__builder""
  IL_0025:  stloc.1
  IL_0026:  ldloca.s   V_1
  IL_0028:  ldloca.s   V_0
  IL_002a:  call       ""void System.Runtime.CompilerServices.AsyncTaskMethodBuilder<object>.Start<<<Initialize>>d__0>(ref <<Initialize>>d__0)""
  IL_002f:  nop
  IL_0030:  ldloc.0
  IL_0031:  ldflda     ""System.Runtime.CompilerServices.AsyncTaskMethodBuilder<object> <<Initialize>>d__0.<>t__builder""
  IL_0036:  call       ""System.Threading.Tasks.Task<object> System.Runtime.CompilerServices.AsyncTaskMethodBuilder<object>.Task.get""
  IL_003b:  ret
}");
            methodData = verifier.TestData.GetMethodData("<Factory>");
            Assert.Equal("System.Threading.Tasks.Task<object>", methodData.Method.ReturnType.ToDisplayString());
            methodData.VerifyIL(
@"{
  // Code size       12 (0xc)
  .maxstack  1
  IL_0000:  ldarg.0
  IL_0001:  newobj     "".ctor(object[])""
  IL_0006:  callvirt   ""System.Threading.Tasks.Task<object> <Initialize>()""
  IL_000b:  ret
}");
        }
Пример #2
0
        public void VerifyHelpers001()
        {
            var source =
                @"
using System.Collections.Generic;

class Program
{
    public static IEnumerable<int> Foo()
    {
        yield return 1;
    }
}

namespace System
{
    class Environment
    {
        public static int CurrentManagedThreadId{get{return 1;}}
    }
}

";
            var parsed = new[] { Parse(source) };
            var comp = CreateCompilationWithMscorlib(parsed);
            comp.MakeMemberMissing(WellKnownMember.System_Threading_Thread__ManagedThreadId);
            var verifier = this.CompileAndVerify(comp);
            var il = verifier.VisualizeIL("Program.<Foo>d__0.System.Collections.Generic.IEnumerable<int>.GetEnumerator()");
            Assert.Contains("System.Environment.CurrentManagedThreadId.get", il, StringComparison.Ordinal);
        }
Пример #3
0
        public void VerifyHelpers()
        {
            var source =
                @"
using System.Collections.Generic;

class Program
{
    public static IEnumerable<int> Foo()
    {
        yield return 1;
    }
}
";
            //EDMAURER ensure that we use System.Environment.CurrentManagedThreadId when compiling against 4.5
            var parsed = new[] { Parse(source) };
            var comp = CreateCompilationWithMscorlib45(parsed);
            var verifier = this.CompileAndVerify(comp);
            var il = verifier.VisualizeIL("Program.<Foo>d__0.System.Collections.Generic.IEnumerable<int>.GetEnumerator()");
            Assert.Contains("System.Environment.CurrentManagedThreadId.get", il, StringComparison.Ordinal);
        }
Пример #4
0
        public void MissingProxyType_SystemCore()
        {
            // "System.Core.dll"
            var source0 = "";
            var compilation0 = CSharpTestBase.CreateCompilationWithMscorlib(source0, assemblyName: "system.core");
            var assembly0 = ReflectionUtilities.Load(compilation0.EmitToArray());
            var source =
@"using System.Collections;
class C : IEnumerable
{
    private readonly IEnumerable e;
    internal C(IEnumerable e)
    {
        this.e = e;
    }
    public IEnumerator GetEnumerator()
    {
        return this.e.GetEnumerator();
    }
}";
            var assembly = GetAssembly(source);
            var assemblies = new[] { assembly0, assembly };
            using (ReflectionUtilities.LoadAssemblies(assemblies))
            {
                var runtime = new DkmClrRuntimeInstance(assemblies);
                var type = assembly.GetType("C");
                var value = CreateDkmClrValue(
                    value: type.Instantiate(new[] { 1, 2 }),
                    type: runtime.GetType((TypeImpl)type));
                var evalResult = FormatResult("o", value);
                Verify(evalResult,
                    EvalResult("o", "{C}", "C", "o", DkmEvaluationResultFlags.Expandable));
                var children = GetChildren(evalResult);
                Verify(children,
                    EvalResult("e", "{int[2]}", "System.Collections.IEnumerable {int[]}", "o.e", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly));
                // Verify the module was found but ResolveTypeName failed.
                var module = runtime.Modules.Single(m => m.Assembly == assembly0);
                Assert.Equal(module.ResolveTypeNameFailures, 1);
            }
        }
Пример #5
0
        public void MissingProxyType()
        {
            var source =
@"using System.Collections;
class C : IEnumerable
{
    private readonly IEnumerable e;
    internal C(IEnumerable e)
    {
        this.e = e;
    }
    public IEnumerator GetEnumerator()
    {
        return this.e.GetEnumerator();
    }
}";
            var assembly = GetAssembly(source);
            var assemblies = new[] { assembly };
            using (ReflectionUtilities.LoadAssemblies(assemblies))
            {
                var runtime = new DkmClrRuntimeInstance(assemblies);
                var type = assembly.GetType("C");
                var value = CreateDkmClrValue(
                    value: type.Instantiate(new[] { 1, 2 }),
                    type: runtime.GetType((TypeImpl)type));
                var evalResult = FormatResult("o", value);
                Verify(evalResult,
                    EvalResult("o", "{C}", "C", "o", DkmEvaluationResultFlags.Expandable));
                var children = GetChildren(evalResult);
                Verify(children,
                    EvalResult("e", "{int[2]}", "System.Collections.IEnumerable {int[]}", "o.e", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly));
            }
        }
        public void TestConditionalOperatorForImplicitConv()
        {
            var source = @"
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        System.Console.WriteLine(false ? Enumerable.Empty<int>() : new int[] { 1 });
    }
}
";
            string expectedOutput = @"System.Int32[]";
            string expectedIL = @"{
  // Code size       16 (0x10)
  .maxstack  4
  IL_0000:  ldc.i4.1  
  IL_0001:  newarr     ""int""
  IL_0006:  dup       
  IL_0007:  ldc.i4.0  
  IL_0008:  ldc.i4.1  
  IL_0009:  stelem.i4 
  IL_000a:  call       ""void System.Console.WriteLine(object)""
  IL_000f:  ret       
}";
            MetadataReference[] metadataRef = new[] { LinqAssemblyRef };

            // Dev11 compiler reports WRN_UnreachableExpr, but reachability is defined for statements not for expressions.
            // We don't report the warning.
            CompileAndVerify(source, additionalRefs: metadataRef, expectedOutput: expectedOutput).VerifyIL("Program.Main", expectedIL).VerifyDiagnostics();
        }