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

Fix error message when trying to use using-static with an invalid type #68571

Merged
merged 5 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 15 additions & 0 deletions src/Compilers/CSharp/Portable/CSharpResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,18 @@
<data name="IDS_SK_TYVAR" xml:space="preserve">
<value>type parameter</value>
</data>
<data name="IDS_SK_ARRAY" xml:space="preserve">
<value>array</value>
</data>
<data name="IDS_SK_POINTER" xml:space="preserve">
<value>pointer</value>
</data>
<data name="IDS_SK_FUNCTION_POINTER" xml:space="preserve">
<value>function pointer</value>
</data>
<data name="IDS_SK_DYNAMIC" xml:space="preserve">
<value>dynamic</value>
</data>
<data name="IDS_SK_ALIAS" xml:space="preserve">
<value>using alias</value>
</data>
Expand Down Expand Up @@ -7511,4 +7523,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="ERR_UnsupportedPrimaryConstructorParameterCapturingRefAny" xml:space="preserve">
<value>Cannot use primary constructor parameter of type '{0}' inside an instance member</value>
</data>
<data name="ERR_BadUsingStaticType" xml:space="preserve">
<value>'{0}' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate or namespace can be used.</value>
Copy link
Member

@Youssef1313 Youssef1313 Jun 13, 2023

Choose a reason for hiding this comment

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

Suggested change
<value>'{0}' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate or namespace can be used.</value>
<value>'{0}' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate, or namespace can be used</value>

</data>
</root>
2 changes: 2 additions & 0 deletions src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2192,6 +2192,8 @@ internal enum ErrorCode
ERR_ConstantValueOfTypeExpected = 9135,
ERR_UnsupportedPrimaryConstructorParameterCapturingRefAny = 9136,

ERR_BadUsingStaticType = 9137,

#endregion

// Note: you will need to do the following after adding warnings:
Expand Down
5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/Errors/MessageID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ internal enum MessageID
IDS_FeatureAutoPropertyInitializer = MessageBase + 12649,

IDS_SK_TYPE_OR_NAMESPACE = MessageBase + 12652,
IDS_SK_ARRAY = MessageBase + 12653,
IDS_SK_POINTER = MessageBase + 12654,
IDS_SK_FUNCTION_POINTER = MessageBase + 12655,
IDS_SK_DYNAMIC = MessageBase + 12656,

IDS_Contravariant = MessageBase + 12659,
IDS_Contravariantly = MessageBase + 12660,
IDS_Covariant = MessageBase + 12661,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,10 @@ UsingsAndDiagnostics buildUsings(
}
}
}
else if (imported.Kind is SymbolKind.ArrayType or SymbolKind.PointerType or SymbolKind.FunctionPointerType or SymbolKind.DynamicType)
{
diagnostics.Add(ErrorCode.ERR_BadUsingStaticType, usingDirective.NamespaceOrType.Location, imported.GetKindText());
}
else if (imported.Kind != SymbolKind.ErrorType)
{
// Do not report additional error if the symbol itself is erroneous.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ public static LocalizableErrorArgument Localize(this SymbolKind kind)
return MessageID.IDS_SK_TYPE.Localize();
case SymbolKind.TypeParameter:
return MessageID.IDS_SK_TYVAR.Localize();
case SymbolKind.ArrayType:
return MessageID.IDS_SK_ARRAY.Localize();
case SymbolKind.PointerType:
return MessageID.IDS_SK_POINTER.Localize();
case SymbolKind.FunctionPointerType:
return MessageID.IDS_SK_FUNCTION_POINTER.Localize();
case SymbolKind.DynamicType:
return MessageID.IDS_SK_DYNAMIC.Localize();
case SymbolKind.Method:
return MessageID.IDS_SK_METHOD.Localize();
case SymbolKind.Property:
Expand Down
25 changes: 25 additions & 0 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.

25 changes: 25 additions & 0 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.

25 changes: 25 additions & 0 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.

25 changes: 25 additions & 0 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.

25 changes: 25 additions & 0 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.

25 changes: 25 additions & 0 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.

25 changes: 25 additions & 0 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.

25 changes: 25 additions & 0 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.

Loading