Skip to content

Commit 3f1b9b0

Browse files
authored
Allow using /main with top-level statements (#79577)
* Allow using `/main` with top-level statements * Verify output in a pre-existing test
1 parent 7ead97f commit 3f1b9b0

18 files changed

+65
-89
lines changed

src/Compilers/CSharp/Portable/CSharpResources.resx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6575,9 +6575,6 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
65756575
<data name="ERR_TopLevelStatementAfterNamespaceOrType" xml:space="preserve">
65766576
<value>Top-level statements must precede namespace and type declarations.</value>
65776577
</data>
6578-
<data name="ERR_SimpleProgramDisallowsMainType" xml:space="preserve">
6579-
<value>Cannot specify /main if there is a compilation unit with top-level statements.</value>
6580-
</data>
65816578
<data name="ERR_SimpleProgramNotAnExecutable" xml:space="preserve">
65826579
<value>Program using top-level statements must be an executable.</value>
65836580
</data>

src/Compilers/CSharp/Portable/Compilation/CSharpCompilation.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,15 +1899,6 @@ internal EntryPoint GetEntryPointAndDiagnostics(CancellationToken cancellationTo
18991899
var entryPointMethod = FindEntryPoint(simpleProgramEntryPointSymbol, cancellationToken, out diagnostics);
19001900
entryPoint = new EntryPoint(entryPointMethod, diagnostics);
19011901
}
1902-
1903-
if (this.Options.MainTypeName != null && simpleProgramEntryPointSymbol is object)
1904-
{
1905-
var diagnostics = DiagnosticBag.GetInstance();
1906-
diagnostics.Add(ErrorCode.ERR_SimpleProgramDisallowsMainType, NoLocation.Singleton);
1907-
entryPoint = new EntryPoint(entryPoint.MethodSymbol,
1908-
new ReadOnlyBindingDiagnostic<AssemblySymbol>(
1909-
entryPoint.Diagnostics.Diagnostics.Concat(diagnostics.ToReadOnlyAndFree()), entryPoint.Diagnostics.Dependencies));
1910-
}
19111902
}
19121903

19131904
Interlocked.CompareExchange(ref _lazyEntryPoint, entryPoint, null);

src/Compilers/CSharp/Portable/Errors/ErrorCode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1815,7 +1815,7 @@ internal enum ErrorCode
18151815
ERR_SimpleProgramLocalIsReferencedOutsideOfTopLevelStatement = 8801,
18161816
ERR_SimpleProgramMultipleUnitsWithTopLevelStatements = 8802,
18171817
ERR_TopLevelStatementAfterNamespaceOrType = 8803,
1818-
ERR_SimpleProgramDisallowsMainType = 8804,
1818+
// ERR_SimpleProgramDisallowsMainType = 8804,
18191819
ERR_SimpleProgramNotAnExecutable = 8805,
18201820

18211821
ERR_UnsupportedCallingConvention = 8806,

src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2074,7 +2074,6 @@ or ErrorCode.ERR_PartialMemberExtendedModDifference
20742074
or ErrorCode.ERR_SimpleProgramLocalIsReferencedOutsideOfTopLevelStatement
20752075
or ErrorCode.ERR_SimpleProgramMultipleUnitsWithTopLevelStatements
20762076
or ErrorCode.ERR_TopLevelStatementAfterNamespaceOrType
2077-
or ErrorCode.ERR_SimpleProgramDisallowsMainType
20782077
or ErrorCode.ERR_SimpleProgramNotAnExecutable
20792078
or ErrorCode.ERR_UnsupportedCallingConvention
20802079
or ErrorCode.ERR_InvalidFunctionPointerCallingConvention

src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)