Skip to content

Re: Why can't we declare a top-level delegate returning a value-tuple? #67311

@Odepax

Description

@Odepax

Version Used: #error version reports Compiler version: '4.5.0-2.22527.10 (401447a2)'. Language version: 10.0.

Steps to Reproduce:

  1. See discussion: Why can't we declare a top-level delegate returning a value-tuple?

    In the following Program.cs listing, only the second to last delegate, I() gives off compile errors.

    System.Console.WriteLine("Hello");
    
    delegate int F(int x);
    delegate int G((int, int) x);
    delegate System.ValueTuple<int, int> H(int x);
    delegate (int, int) I(int x);
    class _ {
       delegate (int, int) J(int x);
    }

    As if to compensate for its uniqueness, it gives off tons of errors, actually:

     1: error CS8803: Top-level statements must precede namespace and type declarations.
    14: error CS1001: Identifier expected
    19: error CS1001: Identifier expected
    21: error CS1514: { expected
    21: error CS1002: ; expected
    23: error CS1525: Invalid expression term 'int'
    27: error CS1003: Syntax error, ',' expected
    

    ... But not one that would help me understand how I angered the compiler.

    Just wondering. 😗

  2. The above using sharplab.

Diagnostic Id: No IDE... diagnostic to show.
Expected Behavior: We can declare value-tuple-returning delegates at top-level.
Actual Behavior: We can't.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions