Skip to content

Commit

Permalink
Disallow in script
Browse files Browse the repository at this point in the history
  • Loading branch information
chsienki committed Feb 11, 2022
1 parent 7d10648 commit 1c26df5
Show file tree
Hide file tree
Showing 16 changed files with 46 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/CSharpResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3975,7 +3975,7 @@ You should consider suppressing the warning only if you're sure that you don't w
<value>Cannot declare namespace in script code</value>
</data>
<data name="ERR_GlobalAttributesNotAllowed" xml:space="preserve">
<value>Assembly and module attributes are not allowed in this context</value>
<value>Assembly, module, and main attributes are not allowed in this context</value>
</data>
<data name="ERR_InvalidDelegateType" xml:space="preserve">
<value>Delegate '{0}' has no invoke method or an invoke method with a return type or parameter types that are not supported.</value>
Expand Down
1 change: 1 addition & 0 deletions src/Compilers/CSharp/Portable/Symbols/Symbol_Attributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ private static bool MatchAttributeTarget(IAttributeTargetSymbol attributeTarget,
{
case AttributeLocation.Assembly:
case AttributeLocation.Module:
case AttributeLocation.Main:
// global attributes are disallowed in interactive code:
diagnostics.Add(ErrorCode.ERR_GlobalAttributesNotAllowed, targetOpt.Identifier.GetLocation());
break;
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions src/Compilers/CSharp/Test/Emit2/Attributes/AttributeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5194,6 +5194,24 @@ public class MyAttribute : Attribute {{ public MyAttribute(string name) {{}} }}
});
}

[Fact]
public void TestMainAttributesInScript()
{
var compilation = CreateSubmission(@"
using System;
[main: My(""one"")]

public class C {}
public class MyAttribute : Attribute { public MyAttribute(string name) {} }",
parseOptions: TestOptions.Script.WithLanguageVersion(LanguageVersion.Preview));

compilation.VerifyDiagnostics(
// (3,2): error CS7026: Assembly and module attributes are not allowed in this context
// [main: My("one")]
Diagnostic(ErrorCode.ERR_GlobalAttributesNotAllowed, "main").WithLocation(3, 2)
);
}

#endregion

#region Error Tests
Expand Down

0 comments on commit 1c26df5

Please sign in to comment.