Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report all-empty top level statements. #54385

Merged
merged 3 commits into from
Jun 25, 2021
Merged

Conversation

AlekseyTs
Copy link
Contributor

Fixes #53472.

@AlekseyTs AlekseyTs requested review from jcouv and a team June 25, 2021 15:21
Comment on lines +78 to +81
if (!topLevelStatement.IsKind(SyntaxKind.EmptyStatement))
{
hasNonEmptyGlobalSatement = true;
}
Copy link
Member

@Youssef1313 Youssef1313 Jun 25, 2021

Choose a reason for hiding this comment

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

Should the error be reported if the top-level program contains only local functions?

i.e,

using System;;

//void M() { } // Currently, uncommenting this line will make the error goes away if I interpret the implementation correctly.

class Program {}
``` #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should the error be reported if the top-level program contains only local functions?

#53472 (comment) - "LDM decided to make it an error if all top-level statements are empty." I do not see LDM deciding anyjthing about local function statements.

Copy link
Member

Choose a reason for hiding this comment

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

@AlekseyTs Yeah I see the PR matches LDM decision, but I mean, was that considered?

The goal of the error is to tell the user "your program will execute nothing and just return 0 immediately", which is the case when the top-level statements are local functions.

Copy link
Contributor Author

@AlekseyTs AlekseyTs Jun 25, 2021

Choose a reason for hiding this comment

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

The goal of the error is to tell the user "your program will execute nothing and just return 0 immediately",

I do not think that is the goal, an entry point function is always executed. There is plenty of ways to write code that does nothing even when it has non-empty statements. We were addressing specific customers scenario and I don't think there was a goal to generalize the issue. If you feel that the issue should be generailized, open an issue and provide your reasons. I beleive a local function that is never called produces a warning, in my opinion that is good enough to give a hint that the code probably doesn't do what was intended.

@AlekseyTs
Copy link
Contributor Author

@jcouv, @dotnet/roslyn-compiler For the second review.

diagnostics = bag.ToReadOnlyAndFree();
}

childrenBuilder.Add(CreateSimpleProgram(firstGlobalStatement, hasAwaitExpressions, isIterator, hasReturnWithExpression, diagnostics));
Copy link
Member

@jcouv jcouv Jun 25, 2021

Choose a reason for hiding this comment

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

nit: extra empty line below #Resolved


var comp = CreateCompilation(text, options: TestOptions.DebugExe, parseOptions: DefaultParseOptions);
CompileAndVerify(comp, expectedOutput: "Hi!");
}
Copy link
Member

@jcouv jcouv Jun 25, 2021

Choose a reason for hiding this comment

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

nit: Consider adding a test from the original issue using System; ; or something like it #Resolved

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM Thanks (iteration 2)

@jcouv jcouv self-assigned this Jun 25, 2021
@AlekseyTs AlekseyTs enabled auto-merge (squash) June 25, 2021 16:33
@AlekseyTs AlekseyTs disabled auto-merge June 25, 2021 16:36
@AlekseyTs AlekseyTs enabled auto-merge (squash) June 25, 2021 16:48
@AlekseyTs AlekseyTs merged commit 2941ae1 into dotnet:main Jun 25, 2021
@ghost ghost added this to the Next milestone Jun 25, 2021
333fred added a commit that referenced this pull request Jun 25, 2021
…ures/caller-argument-expression

* upstream/main: (492 commits)
  Add nullable ref annotations to SyntaxFactory (#54199)
  Add 'replace' APIs and hook them up to the IDE (#54270)
  Allow implicit implementation of non-public interface members (#54182)
  Make insertion a stage of the official build (#54376)
  Cleanup
  Remove unused property
  Simplify glyph computation
  Report all-empty top level statements. (#54385)
  Calculate TypeParameterKind based on the container type (#54200)
  vert
  not roaming
  Split tests
  Multple matches
  Report as we get results
  Fixup tests
  Update tests
  Avoid thread dependency in VirtualMemoryNotificationListener constructor
  Fast progression search.
  Add LanguageVersion 10 (#54359)
  Sure, why not
  ...
@RikkiGibson RikkiGibson modified the milestones: Next, 17.0.P2 Jun 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stray semicolon above namespace keyword causes warning CS7022 and unexpected exit
5 participants