Created
March 9, 2016 02:58
-
-
Save jcouv/03517507739c74165336 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void DynamicLocalCapturedByLambda() | |
{ | |
var mslib = @" | |
namespace System | |
{ | |
public class Object { } | |
public struct Int32 { } | |
public class ValueType { } | |
public class Attribute { } | |
public struct Void { } | |
public struct IntPtr { } | |
public class Type { | |
public static Type GetTypeFromHandle(RuntimeTypeHandle handle ) { return null; } | |
} | |
public struct RuntimeTypeHandle { } | |
public class String { } | |
public delegate void Action(); | |
public class MulticastDelegate : Delegate { } | |
public class Delegate { } | |
}"; | |
var source = @" | |
class C | |
{ | |
void M() | |
{ | |
dynamic local = 42; | |
System.Action lambda = () => { | |
dynamic i = local; | |
}; | |
} | |
} | |
"; | |
// Build an mscorlib including String | |
var mslibComp = CreateCompilation(new string[] { mslib }).VerifyDiagnostics(); | |
var mslibRef = mslibComp.EmitToImageReference(); | |
var comp = CreateCompilation(source, references: new[] { mslibRef, CSharpRef}); | |
comp.VerifyDiagnostics(); | |
CompileAndVerify(comp); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment