Skip to content

Parens: tweak sensitive indentation handling - #16248

Merged
T-Gro merged 9 commits into
dotnet:mainfrom
brianrourkeboll:parens-outer-sensitive-indentation
Nov 14, 2023
Merged

Parens: tweak sensitive indentation handling#16248
T-Gro merged 9 commits into
dotnet:mainfrom
brianrourkeboll:parens-outer-sensitive-indentation

Conversation

@brianrourkeboll

@brianrourkebollbrianrourkeboll commented Nov 9, 2023

Copy link
Copy Markdown
Contributor

Another followup to #16079.

  • Dedent by one space in certain scenarios.

There are certain cases where we must consider both the context outside of a pair of parentheses as well as the inside in order to reintegrate the inner construct into the outer context after removing the parentheses. That is, sometimes we cannot simply remove the parentheses in place, but we must instead shift the entire parenthesized multiline expression left by one space.

For example:

let_=1,(true||false||true),1

must become

let_=1,true||false||true,1

not

let_=1,true||false||true,1

Or here's a real-world example from FSharp.Core:

ty.InvokeMember(
name,
(BindingFlags.GetProperty
||| BindingFlags.Instance
||| BindingFlags.Public
||| BindingFlags.NonPublic),
null,
obj,
[||],
CultureInfo.InvariantCulture
)

* There are certain scenarios where we must consider both the context
outside of a pair of parentheses as well as the inside in order to
reintegrate the inner construct into the outer context after removing
the parentheses.
@brianrourkeboll
brianrourkeboll requested a review from a team as a code ownerNovember 9, 2023 20:00

@psfinakipsfinaki left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cool, thanks!

@psfinaki
psfinaki enabled auto-merge (squash) November 10, 2023 13:15
@brianrourkeboll

Copy link
Copy Markdown
ContributorAuthor

Hmm, I think I see one bug... Let me fix that.

@brianrourkeboll

Copy link
Copy Markdown
ContributorAuthor

Tricky, tricky:

sourceEvent.Add(fun args2 ->
(match lastArgs with
| None ->()
| Some args1 -> ev.Trigger(args1, args2))
lastArgs <- Some args2)

@brianrourkeboll

Copy link
Copy Markdown
ContributorAuthor

Expect some more PRs after this one, unfortunately—running fix-all on FSharp.Core is surfacing some other oddities I hadn't thought of, like the fact that parens aren't needed after new in this:

typeT(x,y)=new(x)= T (x,3)// Can remove parens: `new x = T (x, 3)`.

or in this:

typeT(x,y)=new(x,y,z)= T (x, y)new(x)= T (x,3)// Can remove parens: `new x = T (x, 3)`.

but they are required if there's another constructor and it comes after:

typeT(x,y)=new(x)= T (x,3)// Cannot remove; removing the parens causes parse errors below.new(x,y,_z)= T (x, y)

Or the fact that this is fine:

typeC=abstractM :unit->unitlet_={new C withoverride_.M()=()}// I.e., `override _.M (())` can be simplified to `override _.M ()`

but this requires (()) for the override:

typeC<'T>=abstractM :'T->unitlet_={new C<unit>withoverride_.M(())=()}

Real example:

letStringBuilderPrintfEnv<'Result>(k,buf)=
{new PrintfEnv<Text.StringBuilder, unit, 'Result>(buf)with
override_.Finish():'Result = k ()
override_.Write(s:string)= ignore(buf.Append s)
override_.WriteT(())=()}

@psfinaki

Copy link
Copy Markdown
Contributor

We are totally ready for the followups :)
Yeah looks like you are facing more and more inconsistencies in the compiler... Feel free to create issues about those, we might do something with the parser to eliminate some root causes.

@psfinaki

Copy link
Copy Markdown
Contributor

@brianrourkeboll this LGTM - is there anything else you plan to add here?

@brianrourkeboll

brianrourkeboll commented Nov 14, 2023

Copy link
Copy Markdown
ContributorAuthor

@brianrourkeboll this LGTM - is there anything else you plan to add here?

@psfinaki Nope, this one should be all set.

@T-Gro
T-Gro merged commit d16430f into dotnet:mainNov 14, 2023
@brianrourkeboll
brianrourkeboll deleted the parens-outer-sensitive-indentation branch November 14, 2023 13:45
@majocha

Copy link
Copy Markdown
Contributor

It seems this test case started to fail at some point:

Apparently because it's not being caught by the diagnostics.

Sign up for freeto 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

@brianrourkeboll@psfinaki@majocha@T-Gro