Skip to content

Conversation

@T-Gro
Copy link
Member

@T-Gro T-Gro commented Nov 27, 2023

Addresses #16342 .

The offending code is the following:

type Seq =
   static meme average (x: int seq) = x |> Seq.map float |> Seq.average;;

What happens is that 'meme' is treating as the function name, and average and x become arguments to it.
Instead, this should report an error about not having static followed by member.

The parser recovery remains the same, but now produces an error as it should - see the diff in SyntaxTreeTests.

@T-Gro T-Gro requested a review from a team as a code owner November 27, 2023 12:48
@T-Gro T-Gro requested a review from auduchinok November 27, 2023 12:48
Copy link
Member

@auduchinok auduchinok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've looked into the failures, and it seems this approach is not the best fit here, unfortunately.
Consider this case:

module Module

type T =

    static

    do ()

This is the relevant part of the tokens:

MODULE_IS_HERE (1,0--1,6)
IDENT (1,7--1,13)
OBLOCKBEGIN (3,0--3,4)
  TYPE_COMING_SOON (3,0--3,4)
  TYPE_COMING_SOON (3,0--3,4)
  TYPE_COMING_SOON (3,0--3,4)
  TYPE_COMING_SOON (3,0--3,4)
  TYPE_COMING_SOON (3,0--3,4)
  TYPE_COMING_SOON (3,0--3,4)
  TYPE_IS_HERE (3,0--3,4)
  IDENT (3,5--3,6)
  EQUALS (3,7--3,8)
  OBLOCKBEGIN (5,4--5,10)
    STATIC (5,4--5,10)
    OBLOCKSEP (5,11--7,4)
    ODO (7,4--7,6)
    OBLOCKBEGIN (7,7--7,8)

We only have one token, OBLOCKSEP, to both recover at and to separate the declarations. It'd be much easier if there was a new block after static, but we probably have not enough tokens for LexFilter to insert it.

I think we should probably try checking flagsBuilderAndLeadingKeyword inside memberCore instead and reporting a manually defined error. It may be much simpler to do than to try to recover using different ways and will keep the failed cases working.

@T-Gro
Copy link
Member Author

T-Gro commented Nov 27, 2023

memberCore

Excellent investigation, let me try your proposal then.

@T-Gro
Copy link
Member Author

T-Gro commented Nov 27, 2023

@auduchinok : This looks cleaner now, none of the existing recovery scenarios is touched by it.
The change seems to only affect the new test case (static meme) added - let's see if the full CI check finds anything else.

T-Gro and others added 2 commits November 30, 2023 11:39
@vzarytovskii vzarytovskii enabled auto-merge (squash) November 30, 2023 11:01
@vzarytovskii vzarytovskii merged commit fb767e9 into dotnet:main Nov 30, 2023
@T-Gro T-Gro deleted the 16342-regression-static-member-can-be-defined-without-member-keyword-in-unexpected-way branch November 30, 2023 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants