Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3260,7 +3260,9 @@ private BoundNode BindSimpleProgramCompilationUnit(CompilationUnitSyntax compila
}
}

return FinishBindBlockParts(compilationUnit, boundStatements.ToImmutableAndFree(), diagnostics);
return new BoundNonConstructorMethodBody(compilationUnit,
FinishBindBlockParts(compilationUnit, boundStatements.ToImmutableAndFree(), diagnostics).MakeCompilerGenerated(),
expressionBody: null);
}

private BoundNode BindConstructorBody(ConstructorDeclarationSyntax constructor, DiagnosticBag diagnostics)
Expand Down
3 changes: 3 additions & 0 deletions src/Compilers/CSharp/Portable/CSharpResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -6067,4 +6067,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="ERR_TopLevelStatementAfterNamespaceOrType" xml:space="preserve">
<value>Top-level statements must precede namespace and type declarations.</value>
</data>
<data name="ERR_SimpleProgramDisallowsMainType" xml:space="preserve">
<value>Cannot specify /main if there is a compilation unit with top-level statements.</value>
</data>
</root>
22 changes: 11 additions & 11 deletions src/Compilers/CSharp/Portable/Compilation/CSharpCompilation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1546,17 +1546,10 @@ internal bool DeclaresTheObjectClass
EntryPoint? entryPoint = null;
MethodSymbol? simpleProgramEntryPointSymbol = SimpleProgramNamedTypeSymbol.GetSimpleProgramEntryPoint(this);

if (this.Options.MainTypeName != null)
if (this.Options.MainTypeName != null && !this.Options.MainTypeName.IsValidClrTypeName())
{
if (simpleProgramEntryPointSymbol is object)
{
// PROTOTYPE(SimplePrograms): Report an error that MainTypeName shouldn't be specified
}
else if (!this.Options.MainTypeName.IsValidClrTypeName())
{
Debug.Assert(!this.Options.Errors.IsDefaultOrEmpty);
entryPoint = new EntryPoint(null, ImmutableArray<Diagnostic>.Empty);
}
Debug.Assert(!this.Options.Errors.IsDefaultOrEmpty);
entryPoint = new EntryPoint(null, ImmutableArray<Diagnostic>.Empty);
}

if (entryPoint is null)
Expand All @@ -1566,6 +1559,13 @@ internal bool DeclaresTheObjectClass
entryPoint = new EntryPoint(entryPointMethod, diagnostics);
}

if (this.Options.MainTypeName != null && simpleProgramEntryPointSymbol is object)
{
var diagnostics = DiagnosticBag.GetInstance();
diagnostics.Add(ErrorCode.ERR_SimpleProgramDisallowsMainType, NoLocation.Singleton);
entryPoint = new EntryPoint(entryPoint.MethodSymbol, entryPoint.Diagnostics.Concat(diagnostics.ToReadOnlyAndFree()));
}

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

Expand All @@ -1585,7 +1585,7 @@ internal bool DeclaresTheObjectClass
NamespaceSymbol globalNamespace = this.SourceModule.GlobalNamespace;
var scriptClass = this.ScriptClass;

if (simpleProgramEntryPointSymbol is null && mainTypeName != null)
if (mainTypeName != null)
{
// Global code is the entry point, ignore all other Mains.
if (scriptClass is object)
Expand Down
1 change: 1 addition & 0 deletions src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1776,6 +1776,7 @@ internal enum ErrorCode
ERR_SimpleProgramLocalIsReferencedOutsideOfTopLevelStatement = 9000,
ERR_SimpleProgramMultipleUnitsWithTopLevelStatements = 9001,
ERR_TopLevelStatementAfterNamespaceOrType = 9002,
ERR_SimpleProgramDisallowsMainType = 9003,

// Note: you will need to re-generate compiler code after adding warnings (eng\generate-compiler-code.cmd)
}
Expand Down
18 changes: 13 additions & 5 deletions src/Compilers/CSharp/Portable/Parser/LanguageParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2088,6 +2088,7 @@ private MemberDeclarationSyntax ParseMemberDeclarationOrStatementCore(SyntaxKind
// All modifiers that might start an expression are processed above.
this.ParseModifiers(modifiers, forAccessors: false);
bool haveModifiers = (modifiers.Count > 0);
MemberDeclarationSyntax result;

// Check for constructor form
if (this.CurrentToken.Kind == SyntaxKind.IdentifierToken && this.PeekToken(1).Kind == SyntaxKind.OpenParenToken)
Expand All @@ -2100,24 +2101,31 @@ private MemberDeclarationSyntax ParseMemberDeclarationOrStatementCore(SyntaxKind
// missing ';'
//
// Unless modifiers or attributes are present this is more likely to be a method call than a method definition.
if ((haveAttributes && IsScript) || haveModifiers)
if (haveAttributes || haveModifiers)
{
var token = SyntaxFactory.MissingToken(SyntaxKind.VoidKeyword);
token = this.AddError(token, ErrorCode.ERR_MemberNeedsType);
var voidType = _syntaxFactory.PredefinedType(token);

var identifier = this.EatToken();

// PROTOTYPE(SimplePrograms): Should we parse this as a local function for Simple Programs in some scenarios?
return this.ParseMethodDeclaration(attributes, modifiers, voidType, explicitInterfaceOpt: null, identifier: identifier, typeParameterList: null);
if (!IsScript)
{
if (tryParseLocalDeclarationStatementFromStartPoint<LocalFunctionStatementSyntax>(attributes, ref afterAttributesPoint, out result))
{
return result;
}
}
else
{
return this.ParseMethodDeclaration(attributes, modifiers, voidType, explicitInterfaceOpt: null, identifier: identifier, typeParameterList: null);
}
}
}

// Destructors are disallowed in global code, skipping check for them.
// TODO: better error messages for script

MemberDeclarationSyntax result;

// Check for constant
if (this.CurrentToken.Kind == SyntaxKind.ConstKeyword)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ protected override Location GetCorrespondingBaseListLocation(NamedTypeSymbol @ba
}

internal override NamedTypeSymbol BaseTypeNoUseSiteDiagnostics
=> this.DeclaringCompilation.GetSpecialType(Microsoft.CodeAnalysis.SpecialType.System_Object); // PROTOTYPE(SimplePrograms): Test with missing Object type.
=> this.DeclaringCompilation.GetSpecialType(Microsoft.CodeAnalysis.SpecialType.System_Object);

protected override void CheckBase(DiagnosticBag diagnostics)
{
// check that System.Object is available.
var info = this.DeclaringCompilation.GetSpecialType(SpecialType.System_Object).GetUseSiteDiagnostic();
if (info != null)
{
Symbol.ReportUseSiteDiagnostic(info, diagnostics, Locations[0]);
Symbol.ReportUseSiteDiagnostic(info, diagnostics, NoLocation.Singleton);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,10 @@ internal SynthesizedSimpleProgramEntryPointSymbol(SimpleProgramNamedTypeSymbol c

if (hasAwait)
{
// PROTOTYPE(SimplePrograms): Test with missing Task type.
_returnType = Binder.GetWellKnownType(containingType.DeclaringCompilation, WellKnownType.System_Threading_Tasks_Task, diagnostics, NoLocation.Singleton);
}
else
{
// PROTOTYPE(SimplePrograms): Test with missing Void type.
_returnType = Binder.GetSpecialType(containingType.DeclaringCompilation, SpecialType.System_Void, NoLocation.Singleton, diagnostics);
}

Expand Down
5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@
<target state="translated">Cílový modul runtime nepodporuje pro člena rozhraní přístupnost na úrovni Protected, Protected internal nebo Private protected.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SimpleProgramDisallowsMainType">
<source>Cannot specify /main if there is a compilation unit with top-level statements.</source>
<target state="new">Cannot specify /main if there is a compilation unit with top-level statements.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SimpleProgramLocalIsReferencedOutsideOfTopLevelStatement">
<source>Cannot use local variable or local function '{0}' declared in a top-level statement in this context.</source>
<target state="new">Cannot use local variable or local function '{0}' declared in a top-level statement in this context.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@
<target state="translated">Die Zugriffsoptionen "protected", "protected internal" oder "private protected" werden von der Zielruntime für einen Member einer Schnittstelle nicht unterstützt.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SimpleProgramDisallowsMainType">
<source>Cannot specify /main if there is a compilation unit with top-level statements.</source>
<target state="new">Cannot specify /main if there is a compilation unit with top-level statements.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SimpleProgramLocalIsReferencedOutsideOfTopLevelStatement">
<source>Cannot use local variable or local function '{0}' declared in a top-level statement in this context.</source>
<target state="new">Cannot use local variable or local function '{0}' declared in a top-level statement in this context.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@
<target state="translated">El entorno de ejecución de destino no admite la accesibilidad protegida, protegida interna o protegida privada para un miembro de una interfaz.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SimpleProgramDisallowsMainType">
<source>Cannot specify /main if there is a compilation unit with top-level statements.</source>
<target state="new">Cannot specify /main if there is a compilation unit with top-level statements.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SimpleProgramLocalIsReferencedOutsideOfTopLevelStatement">
<source>Cannot use local variable or local function '{0}' declared in a top-level statement in this context.</source>
<target state="new">Cannot use local variable or local function '{0}' declared in a top-level statement in this context.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@
<target state="translated">Le runtime cible ne prend pas en charge l'accessibilité 'protected', 'protected internal' ou 'private protected' d'un membre d'interface.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SimpleProgramDisallowsMainType">
<source>Cannot specify /main if there is a compilation unit with top-level statements.</source>
<target state="new">Cannot specify /main if there is a compilation unit with top-level statements.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SimpleProgramLocalIsReferencedOutsideOfTopLevelStatement">
<source>Cannot use local variable or local function '{0}' declared in a top-level statement in this context.</source>
<target state="new">Cannot use local variable or local function '{0}' declared in a top-level statement in this context.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@
<target state="translated">Il runtime di destinazione non supporta l'accessibilità 'protected', 'protected internal' o 'private protected' per un membro di un'interfaccia.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SimpleProgramDisallowsMainType">
<source>Cannot specify /main if there is a compilation unit with top-level statements.</source>
<target state="new">Cannot specify /main if there is a compilation unit with top-level statements.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SimpleProgramLocalIsReferencedOutsideOfTopLevelStatement">
<source>Cannot use local variable or local function '{0}' declared in a top-level statement in this context.</source>
<target state="new">Cannot use local variable or local function '{0}' declared in a top-level statement in this context.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@
<target state="translated">ターゲット ランタイムは、インターフェイスのメンバーに対して 'protected'、'protected internal'、'private protected' アクセシビリティをサポートしていません。</target>
<note />
</trans-unit>
<trans-unit id="ERR_SimpleProgramDisallowsMainType">
<source>Cannot specify /main if there is a compilation unit with top-level statements.</source>
<target state="new">Cannot specify /main if there is a compilation unit with top-level statements.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SimpleProgramLocalIsReferencedOutsideOfTopLevelStatement">
<source>Cannot use local variable or local function '{0}' declared in a top-level statement in this context.</source>
<target state="new">Cannot use local variable or local function '{0}' declared in a top-level statement in this context.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@
<target state="translated">대상 런타임이 인터페이스 멤버의 'protected', 'protected internal' 또는 'private protected' 접근성을 지원하지 않습니다.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SimpleProgramDisallowsMainType">
<source>Cannot specify /main if there is a compilation unit with top-level statements.</source>
<target state="new">Cannot specify /main if there is a compilation unit with top-level statements.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SimpleProgramLocalIsReferencedOutsideOfTopLevelStatement">
<source>Cannot use local variable or local function '{0}' declared in a top-level statement in this context.</source>
<target state="new">Cannot use local variable or local function '{0}' declared in a top-level statement in this context.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@
<target state="translated">Docelowe środowisko uruchomieniowe nie obsługuje specyfikatorów dostępu „protected”, „protected internal” i „private protected” dla składowej interfejsu.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SimpleProgramDisallowsMainType">
<source>Cannot specify /main if there is a compilation unit with top-level statements.</source>
<target state="new">Cannot specify /main if there is a compilation unit with top-level statements.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SimpleProgramLocalIsReferencedOutsideOfTopLevelStatement">
<source>Cannot use local variable or local function '{0}' declared in a top-level statement in this context.</source>
<target state="new">Cannot use local variable or local function '{0}' declared in a top-level statement in this context.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@
<target state="translated">O runtime de destino não é compatível com a acessibilidade 'protected', 'protected internal' ou 'private protected' para um membro de uma interface.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SimpleProgramDisallowsMainType">
<source>Cannot specify /main if there is a compilation unit with top-level statements.</source>
<target state="new">Cannot specify /main if there is a compilation unit with top-level statements.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SimpleProgramLocalIsReferencedOutsideOfTopLevelStatement">
<source>Cannot use local variable or local function '{0}' declared in a top-level statement in this context.</source>
<target state="new">Cannot use local variable or local function '{0}' declared in a top-level statement in this context.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@
<target state="translated">Целевая среда выполнения не поддерживает специальные возможности "защищенный", "внутренний защищенный" или "частный защищенный" для члена интерфейса.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SimpleProgramDisallowsMainType">
<source>Cannot specify /main if there is a compilation unit with top-level statements.</source>
<target state="new">Cannot specify /main if there is a compilation unit with top-level statements.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SimpleProgramLocalIsReferencedOutsideOfTopLevelStatement">
<source>Cannot use local variable or local function '{0}' declared in a top-level statement in this context.</source>
<target state="new">Cannot use local variable or local function '{0}' declared in a top-level statement in this context.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@
<target state="translated">Hedef çalışma zamanı, bir arabirim üyesi için 'protected', 'protected internal' veya 'private protected' erişilebilirliğini desteklemez.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SimpleProgramDisallowsMainType">
<source>Cannot specify /main if there is a compilation unit with top-level statements.</source>
<target state="new">Cannot specify /main if there is a compilation unit with top-level statements.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SimpleProgramLocalIsReferencedOutsideOfTopLevelStatement">
<source>Cannot use local variable or local function '{0}' declared in a top-level statement in this context.</source>
<target state="new">Cannot use local variable or local function '{0}' declared in a top-level statement in this context.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@
<target state="translated">目标运行时不支持对接口的成员使用 "protected"、"protected internal" 或 "private protected" 辅助功能。</target>
<note />
</trans-unit>
<trans-unit id="ERR_SimpleProgramDisallowsMainType">
<source>Cannot specify /main if there is a compilation unit with top-level statements.</source>
<target state="new">Cannot specify /main if there is a compilation unit with top-level statements.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SimpleProgramLocalIsReferencedOutsideOfTopLevelStatement">
<source>Cannot use local variable or local function '{0}' declared in a top-level statement in this context.</source>
<target state="new">Cannot use local variable or local function '{0}' declared in a top-level statement in this context.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@
<target state="translated">目標執行階段不支援介面成員的 'protected'、'protected internal' 或 'private protected' 存取權。</target>
<note />
</trans-unit>
<trans-unit id="ERR_SimpleProgramDisallowsMainType">
<source>Cannot specify /main if there is a compilation unit with top-level statements.</source>
<target state="new">Cannot specify /main if there is a compilation unit with top-level statements.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SimpleProgramLocalIsReferencedOutsideOfTopLevelStatement">
<source>Cannot use local variable or local function '{0}' declared in a top-level statement in this context.</source>
<target state="new">Cannot use local variable or local function '{0}' declared in a top-level statement in this context.</target>
Expand Down
Loading