-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Labels
Area-CompilersBugFeature - Out Variable DeclarationOut Variable DeclarationOut Variable DeclarationFeature - Pattern MatchingPattern MatchingPattern MatchingLanguage-C#Resolution-FixedThe bug has been fixed and/or the requested behavior has been implementedThe bug has been fixed and/or the requested behavior has been implemented
Milestone
Description
[Fact]
public void GlobalCode_Lambda_02()
{
var source =
@"
System.Func<bool> l = () => TakeOutParam(1, out int x1) && Dummy(x1);
System.Console.WriteLine(l());
static bool Dummy(int x)
{
System.Console.WriteLine(x);
return true;
}
static bool TakeOutParam(int y, out int x)
{
x = y;
return true;
}
";
var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.ReleaseExe.WithScriptClassName("Script"), parseOptions: TestOptions.Script);
CompileAndVerify(compilation, expectedOutput: @"1
True");
var tree = compilation.SyntaxTrees.Single();
var model = compilation.GetSemanticModel(tree);
var x1Decl = GetOutVarDeclarations(tree, "x1").Single();
var x1Ref = GetReferences(tree, "x1").Single();
VerifyModelForOutVar(model, x1Decl, x1Ref);
}
Result:
(2,49): error CS8200: Out variable and pattern variable declarations are not allowed within constructor initializers, field initializers, or property initializers.
Metadata
Metadata
Assignees
Labels
Area-CompilersBugFeature - Out Variable DeclarationOut Variable DeclarationOut Variable DeclarationFeature - Pattern MatchingPattern MatchingPattern MatchingLanguage-C#Resolution-FixedThe bug has been fixed and/or the requested behavior has been implementedThe bug has been fixed and/or the requested behavior has been implemented