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

Add support for using alias = any_type. #50167

Merged
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
cdf67db
Add parsing of using aliases that point to types.
CyrusNajmabadi Dec 29, 2020
7acfeba
Update API surface.
CyrusNajmabadi Dec 29, 2020
ba290a2
Fix tests
CyrusNajmabadi Dec 30, 2020
4f970f5
Add parsing tests
CyrusNajmabadi Dec 30, 2020
538637f
Add binding support
CyrusNajmabadi Dec 30, 2020
b7adad3
Update IDE side.
CyrusNajmabadi Dec 30, 2020
b64aeac
Add semantic tests
CyrusNajmabadi Dec 30, 2020
984bf0f
Support functptr types
CyrusNajmabadi Dec 30, 2020
b492649
Disallow ref types
CyrusNajmabadi Dec 30, 2020
523de61
Merge remote-tracking branch 'upstream/main' into usingAliasType
CyrusNajmabadi Sep 9, 2021
28c54b4
Merge
CyrusNajmabadi Sep 9, 2021
eb37ef3
Merge remote-tracking branch 'upstream/main' into usingAliasType
CyrusNajmabadi Jan 14, 2023
dda5b30
Fix
CyrusNajmabadi Jan 14, 2023
a314010
Fix
CyrusNajmabadi Jan 14, 2023
c67a9a1
move more cases to type
CyrusNajmabadi Jan 14, 2023
aa49836
Move error
CyrusNajmabadi Jan 14, 2023
27c0fcd
Add unsafe modifier
CyrusNajmabadi Jan 14, 2023
af583bb
Bind with unsafe
CyrusNajmabadi Jan 14, 2023
e2a1d78
No nullable reference types
CyrusNajmabadi Jan 14, 2023
f90faaa
Update apis
CyrusNajmabadi Jan 15, 2023
0185eac
Add apis
CyrusNajmabadi Jan 15, 2023
e6a3b1f
Add api
CyrusNajmabadi Jan 15, 2023
bc8ba4d
Add api
CyrusNajmabadi Jan 15, 2023
313b69c
Add api
CyrusNajmabadi Jan 15, 2023
6aeac08
Fix
CyrusNajmabadi Jan 15, 2023
308acb0
NRT
CyrusNajmabadi Jan 15, 2023
288b7c9
NRT
CyrusNajmabadi Jan 15, 2023
0f12baa
NRT
CyrusNajmabadi Jan 15, 2023
6e7cee3
Fix
CyrusNajmabadi Jan 15, 2023
f81f89f
Move
CyrusNajmabadi Jan 15, 2023
2b27982
Add error facts
CyrusNajmabadi Jan 15, 2023
a5e8b9e
Add error facts
CyrusNajmabadi Jan 15, 2023
9bbda42
Add tests
CyrusNajmabadi Jan 15, 2023
2e6998e
Add tests
CyrusNajmabadi Jan 15, 2023
5dddfc2
Add c# 11 test
CyrusNajmabadi Jan 15, 2023
9e2c969
Add unsafe tests
CyrusNajmabadi Jan 15, 2023
492c9ea
Add unsafe tests
CyrusNajmabadi Jan 15, 2023
74cd663
Dynamic work
CyrusNajmabadi Jan 15, 2023
0fae0b0
Update feature status
CyrusNajmabadi Jan 15, 2023
0eb5ee5
Delete
CyrusNajmabadi Jan 15, 2023
e169a14
Update
CyrusNajmabadi Jan 15, 2023
e5e06c4
Add comment
CyrusNajmabadi Jan 15, 2023
b860116
Fix test
CyrusNajmabadi Jan 15, 2023
972e75a
Fix test
CyrusNajmabadi Jan 15, 2023
54374bd
Fix test
CyrusNajmabadi Jan 15, 2023
42d7759
Add tests
CyrusNajmabadi Jan 15, 2023
82254d4
Add tests
CyrusNajmabadi Jan 15, 2023
28c7cff
Update docs/Language Feature Status.md
CyrusNajmabadi Jan 25, 2023
762bd01
Add tests
CyrusNajmabadi Jan 25, 2023
2c4c046
Add support for top level dynamic
CyrusNajmabadi Jan 25, 2023
9bab6d6
Add support for top level dynamic
CyrusNajmabadi Jan 26, 2023
f78bbd7
Fix loc string
CyrusNajmabadi Jan 26, 2023
275a688
Move into 12.0 section
CyrusNajmabadi Jan 27, 2023
5f3a2c4
Add test
CyrusNajmabadi Jan 27, 2023
3a80d86
Add test
CyrusNajmabadi Jan 27, 2023
8dbb1ec
Move errors to binding
CyrusNajmabadi Jan 27, 2023
087b508
Add tests
CyrusNajmabadi Jan 27, 2023
0f25385
Use file scoped namespace
CyrusNajmabadi Jan 27, 2023
73982a7
Allow aliases to nint/nuint.
CyrusNajmabadi Jan 27, 2023
ef40e33
Add tests
CyrusNajmabadi Jan 27, 2023
4979ff0
Add tests
CyrusNajmabadi Jan 27, 2023
3cf2096
Add comment
CyrusNajmabadi Jan 27, 2023
07a27aa
Update test
CyrusNajmabadi Jan 27, 2023
6321355
Merge remote-tracking branch 'upstream/features/UsingAliasesTypes' in…
CyrusNajmabadi Jan 27, 2023
cb49fae
Merge remote-tracking branch 'upstream/features/UsingAliasesTypes' in…
CyrusNajmabadi Jan 30, 2023
8125da5
'dynamic' should bind to type
CyrusNajmabadi Jan 30, 2023
08279fb
Update docs/Language Feature Status.md
CyrusNajmabadi Jan 30, 2023
3b78a6d
Update tests
CyrusNajmabadi Jan 30, 2023
f7593d3
Merge branch 'usingAliasType' of https://github.com/CyrusNajmabadi/ro…
CyrusNajmabadi Jan 30, 2023
50e0ff4
PR feedback
CyrusNajmabadi Jan 31, 2023
3a5efe6
switch to typesymbol
CyrusNajmabadi Jan 31, 2023
149e5b5
Simplify
CyrusNajmabadi Jan 31, 2023
e154966
Add tests
CyrusNajmabadi Jan 31, 2023
73531cf
Add tests
CyrusNajmabadi Jan 31, 2023
fbf9b8d
Merge remote-tracking branch 'upstream/features/UsingAliasesTypes' in…
CyrusNajmabadi Feb 2, 2023
33ebdbe
Named parameter
CyrusNajmabadi Feb 2, 2023
bcbdcd6
Remove unused usings
CyrusNajmabadi Feb 2, 2023
3e1619a
Improve tests
CyrusNajmabadi Feb 2, 2023
8bffc64
Use RegularPreview
CyrusNajmabadi Feb 2, 2023
b114890
Update tests
CyrusNajmabadi Feb 2, 2023
e056e6b
Fix comment
CyrusNajmabadi Feb 2, 2023
6cc95af
Merge tests
CyrusNajmabadi Feb 2, 2023
b5a3ba3
Merge tests
CyrusNajmabadi Feb 2, 2023
c9d5b90
Add tests
CyrusNajmabadi Feb 2, 2023
97161ee
Syntax test only
CyrusNajmabadi Feb 2, 2023
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
7 changes: 4 additions & 3 deletions src/Compilers/CSharp/Portable/Binder/Imports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public static Imports FromSyntax(
if (usingAliases != null && usingAliases.ContainsKey(identifierValueText))
{
// Suppress diagnostics if we're already broken.
if (!usingDirective.Name.IsMissing)
if (!usingDirective.Type.IsMissing)
{
// The using alias '{0}' appeared previously in this namespace
diagnostics.Add(ErrorCode.ERR_DuplicateAlias, location, identifierValueText);
Expand All @@ -188,11 +188,12 @@ public static Imports FromSyntax(

// construct the alias sym with the binder for which we are building imports. That
// way the alias target can make use of extern alias definitions.
usingAliases.Add(identifierValueText, new AliasAndUsingDirective(new AliasSymbol(usingsBinder, usingDirective.Name, usingDirective.Alias), usingDirective));
usingAliases.Add(identifierValueText, new AliasAndUsingDirective(new AliasSymbol(usingsBinder, usingDirective.Type, usingDirective.Alias), usingDirective));
}
}
else
{
Debug.Assert(usingDirective.Name != null);
if (usingDirective.Name.IsMissing)
{
//don't try to lookup namespaces inserted by parser error recovery
Expand Down Expand Up @@ -593,7 +594,7 @@ private void Validate()
if (@using.NamespaceOrType.IsType)
{
var typeSymbol = (TypeSymbol)@using.NamespaceOrType;
var location = @using.UsingDirective?.Name.Location ?? NoLocation.Singleton;
var location = @using.UsingDirective?.Type.Location ?? NoLocation.Singleton;
typeSymbol.CheckAllConstraints(_compilation, conversions, location, semanticDiagnostics);
}
}
Expand Down
62 changes: 34 additions & 28 deletions src/Compilers/CSharp/Portable/CSharpResources.resx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema

<!--
Microsoft ResX Schema
Version 2.0

The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.

Example:

... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
Expand All @@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>

There are any number of "resheader" rows that contain simple
There are any number of "resheader" rows that contain simple
name/value pairs.

Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.

The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:

Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.

mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
Expand Down Expand Up @@ -6600,4 +6600,10 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="WRN_DoNotCompareFunctionPointers_Title" xml:space="preserve">
<value>Do not compare function pointer values</value>
</data>
</root>
<data name="IDS_FeatureUsingTypeAlias" xml:space="preserve">
<value>using type alias</value>
</data>
<data name="ERR_BadRefInUsingAlias" xml:space="preserve">
<value>Using alias cannot be a 'ref' type.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -1949,7 +1949,7 @@ public override IAliasSymbol GetDeclaredSymbol(
else
{
// Case: multiple aliases, not the first (see DevDiv #9368)
return new AliasSymbol(binder, declarationSyntax.Name, declarationSyntax.Alias).GetPublicSymbol();
return new AliasSymbol(binder, declarationSyntax.Type, declarationSyntax.Alias).GetPublicSymbol();
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1931,6 +1931,12 @@ internal enum ErrorCode

#endregion diagnostics introduced for C# 9.0

#region diagnostics introduced for C# preview
CyrusNajmabadi marked this conversation as resolved.
Show resolved Hide resolved

ERR_BadRefInUsingAlias = 9000,

#endregion

// Note: you will need to re-generate compiler code after adding warnings (eng\generate-compiler-code.cmd)
}
}
3 changes: 3 additions & 0 deletions src/Compilers/CSharp/Portable/Errors/MessageID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ internal enum MessageID
IDS_Return = MessageBase + 12790,
IDS_FeatureVarianceSafetyForStaticInterfaceMembers = MessageBase + 12791,
IDS_FeatureConstantInterpolatedStrings = MessageBase + 12792,

IDS_FeatureUsingTypeAlias = MessageBase + 12800,
Copy link
Member Author

Choose a reason for hiding this comment

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

not sure hte number to pick here. i could make this 12793 if that's appropriate.

Copy link
Member

Choose a reason for hiding this comment

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

This number is fine. It may need to be adjusted when merging to main, but likely there won't be a conflict.

}

// Message IDs may refer to strings that need to be localized.
Expand Down Expand Up @@ -348,6 +350,7 @@ internal static LanguageVersion RequiredVersion(this MessageID feature)
case MessageID.IDS_FeatureDefaultTypeParameterConstraint:
return LanguageVersion.CSharp9;

case MessageID.IDS_FeatureUsingTypeAlias: // syntax check
case MessageID.IDS_FeatureVarianceSafetyForStaticInterfaceMembers: //semantic check
case MessageID.IDS_FeatureConstantInterpolatedStrings: //semantic check
return LanguageVersion.Preview;
Expand Down
Loading