From 2e87b0136771e8a158cf1058cc49e9d55c4ae55b Mon Sep 17 00:00:00 2001 From: Joanna May Date: Mon, 16 Dec 2024 18:18:41 -0600 Subject: [PATCH 1/2] reproduce: global using alias with value type --- .../TypeRegistry.g.cs | 1 + .../Chickensoft.Introspection.Generator.Tests.csproj | 3 +++ .../test_cases/GlobalUsing.cs | 6 ++++++ .../test_cases/GlobalUsingValueType.cs | 3 +++ ...ckensoft.Introspection.OutsideAssemblyForTests.csproj | 9 +++++++++ .../ExampleStruct.cs | 3 +++ .../Chickensoft.Introspection.Tests.csproj | 2 ++ global.json | 4 ++-- 8 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 Chickensoft.Introspection.Generator.Tests/test_cases/GlobalUsing.cs create mode 100644 Chickensoft.Introspection.Generator.Tests/test_cases/GlobalUsingValueType.cs create mode 100644 Chickensoft.Introspection.OutsideAssemblyForTests/Chickensoft.Introspection.OutsideAssemblyForTests.csproj create mode 100644 Chickensoft.Introspection.OutsideAssemblyForTests/ExampleStruct.cs diff --git a/Chickensoft.Introspection.Generator.Tests/.generated/Chickensoft.Introspection.Generator/Chickensoft.Introspection.Generator.TypeGenerator/TypeRegistry.g.cs b/Chickensoft.Introspection.Generator.Tests/.generated/Chickensoft.Introspection.Generator/Chickensoft.Introspection.Generator.TypeGenerator/TypeRegistry.g.cs index e4e5246..297b6ff 100644 --- a/Chickensoft.Introspection.Generator.Tests/.generated/Chickensoft.Introspection.Generator/Chickensoft.Introspection.Generator.TypeGenerator/TypeRegistry.g.cs +++ b/Chickensoft.Introspection.Generator.Tests/.generated/Chickensoft.Introspection.Generator/Chickensoft.Introspection.Generator.TypeGenerator/TypeRegistry.g.cs @@ -43,6 +43,7 @@ public partial class TypeRegistry : Chickensoft.Introspection.ITypeRegistry { [typeof(Chickensoft.Introspection.Generator.Tests.TestCases.ConcreteChildOne)] = new Chickensoft.Introspection.IdentifiableTypeMetadata("ConcreteChildOne", static (r) => r.Receive(), static () => System.Activator.CreateInstance(), new Chickensoft.Introspection.Generator.Tests.TestCases.ConcreteChildOne.MetatypeMetadata(), "concrete_child_one", 1), [typeof(Chickensoft.Introspection.Generator.Tests.TestCases.ConcreteChildTwo)] = new Chickensoft.Introspection.IdentifiableTypeMetadata("ConcreteChildTwo", static (r) => r.Receive(), static () => System.Activator.CreateInstance(), new Chickensoft.Introspection.Generator.Tests.TestCases.ConcreteChildTwo.MetatypeMetadata(), "concrete_child_two", 1), [typeof(Chickensoft.Introspection.Generator.Tests.TestCases.DerivedModel)] = new Chickensoft.Introspection.IntrospectiveTypeMetadata("DerivedModel", static (r) => r.Receive(), static () => System.Activator.CreateInstance(), new Chickensoft.Introspection.Generator.Tests.TestCases.DerivedModel.MetatypeMetadata(), 1), + [typeof(Chickensoft.Introspection.Generator.Tests.TestCases.ExampleStruct)] = new Chickensoft.Introspection.ConcreteTypeMetadata("ExampleStruct", static (r) => r.Receive(), static () => System.Activator.CreateInstance()), [typeof(Chickensoft.Introspection.Generator.Tests.TestCases.GenericStruct<>)] = new Chickensoft.Introspection.TypeMetadata("GenericStruct"), [typeof(Chickensoft.Introspection.Generator.Tests.TestCases.InitArgsModel)] = new Chickensoft.Introspection.IdentifiableTypeMetadata("InitArgsModel", static (r) => r.Receive(), static () => System.Activator.CreateInstance(), new Chickensoft.Introspection.Generator.Tests.TestCases.InitArgsModel.MetatypeMetadata(), "init_args_model", 1), [typeof(Chickensoft.Introspection.Generator.Tests.TestCases.JunkAttribute)] = new Chickensoft.Introspection.ConcreteTypeMetadata("JunkAttribute", static (r) => r.Receive(), static () => System.Activator.CreateInstance()), diff --git a/Chickensoft.Introspection.Generator.Tests/Chickensoft.Introspection.Generator.Tests.csproj b/Chickensoft.Introspection.Generator.Tests/Chickensoft.Introspection.Generator.Tests.csproj index 4c1923f..c981d2d 100644 --- a/Chickensoft.Introspection.Generator.Tests/Chickensoft.Introspection.Generator.Tests.csproj +++ b/Chickensoft.Introspection.Generator.Tests/Chickensoft.Introspection.Generator.Tests.csproj @@ -15,6 +15,8 @@ true + + CA1010;NU1903 @@ -38,6 +40,7 @@ + diff --git a/Chickensoft.Introspection.Generator.Tests/test_cases/GlobalUsing.cs b/Chickensoft.Introspection.Generator.Tests/test_cases/GlobalUsing.cs new file mode 100644 index 0000000..1f2a3c9 --- /dev/null +++ b/Chickensoft.Introspection.Generator.Tests/test_cases/GlobalUsing.cs @@ -0,0 +1,6 @@ +#pragma warning disable IDE0005 // Using directive is unnecessary. +global using MyExampleStruct = + Chickensoft.Introspection.Generator.Tests.TestCases.ExampleStruct; +global using MyOutsideExampleStruct = + Chickensoft.Introspection.OutsideAssemblyForTests.ExampleStruct; +#pragma warning restore IDE0005 // Using directive is unnecessary. diff --git a/Chickensoft.Introspection.Generator.Tests/test_cases/GlobalUsingValueType.cs b/Chickensoft.Introspection.Generator.Tests/test_cases/GlobalUsingValueType.cs new file mode 100644 index 0000000..8290659 --- /dev/null +++ b/Chickensoft.Introspection.Generator.Tests/test_cases/GlobalUsingValueType.cs @@ -0,0 +1,3 @@ +namespace Chickensoft.Introspection.Generator.Tests.TestCases; + +public readonly record struct ExampleStruct; diff --git a/Chickensoft.Introspection.OutsideAssemblyForTests/Chickensoft.Introspection.OutsideAssemblyForTests.csproj b/Chickensoft.Introspection.OutsideAssemblyForTests/Chickensoft.Introspection.OutsideAssemblyForTests.csproj new file mode 100644 index 0000000..d35d8ff --- /dev/null +++ b/Chickensoft.Introspection.OutsideAssemblyForTests/Chickensoft.Introspection.OutsideAssemblyForTests.csproj @@ -0,0 +1,9 @@ + + + + net7.0 + disable + enable + + + diff --git a/Chickensoft.Introspection.OutsideAssemblyForTests/ExampleStruct.cs b/Chickensoft.Introspection.OutsideAssemblyForTests/ExampleStruct.cs new file mode 100644 index 0000000..bcaeb91 --- /dev/null +++ b/Chickensoft.Introspection.OutsideAssemblyForTests/ExampleStruct.cs @@ -0,0 +1,3 @@ +namespace Chickensoft.Introspection.OutsideAssemblyForTests; + +public readonly record struct ExampleStruct; diff --git a/Chickensoft.Introspection.Tests/Chickensoft.Introspection.Tests.csproj b/Chickensoft.Introspection.Tests/Chickensoft.Introspection.Tests.csproj index 047c3f3..203e53d 100644 --- a/Chickensoft.Introspection.Tests/Chickensoft.Introspection.Tests.csproj +++ b/Chickensoft.Introspection.Tests/Chickensoft.Introspection.Tests.csproj @@ -16,6 +16,8 @@ true + + NU1903 diff --git a/global.json b/global.json index 85721c3..2c56923 100644 --- a/global.json +++ b/global.json @@ -1,9 +1,9 @@ { "sdk": { - "version": "7.0.404", + "version": "9.0.100", "rollForward": "latestMinor" }, "msbuild-sdks": { "Godot.NET.Sdk": "4.2.2" } -} +} \ No newline at end of file From e515f59fb06ebb19ddfa6501d6c97a67bca416e9 Mon Sep 17 00:00:00 2001 From: Joanna May Date: Mon, 16 Dec 2024 22:49:18 -0600 Subject: [PATCH 2/2] fix: aliases of predefined types --- .../Chickensoft.Introspection.Generator.Tests.csproj | 3 +-- .../test_cases/GlobalUsing.cs | 3 +-- .../Chickensoft.Introspection.Generator.csproj | 2 +- Chickensoft.Introspection.Generator/src/TypeGenerator.cs | 3 ++- ...ckensoft.Introspection.OutsideAssemblyForTests.csproj | 9 --------- .../ExampleStruct.cs | 3 --- 6 files changed, 5 insertions(+), 18 deletions(-) delete mode 100644 Chickensoft.Introspection.OutsideAssemblyForTests/Chickensoft.Introspection.OutsideAssemblyForTests.csproj delete mode 100644 Chickensoft.Introspection.OutsideAssemblyForTests/ExampleStruct.cs diff --git a/Chickensoft.Introspection.Generator.Tests/Chickensoft.Introspection.Generator.Tests.csproj b/Chickensoft.Introspection.Generator.Tests/Chickensoft.Introspection.Generator.Tests.csproj index c981d2d..dd4ac1c 100644 --- a/Chickensoft.Introspection.Generator.Tests/Chickensoft.Introspection.Generator.Tests.csproj +++ b/Chickensoft.Introspection.Generator.Tests/Chickensoft.Introspection.Generator.Tests.csproj @@ -20,7 +20,7 @@ - + @@ -40,7 +40,6 @@ - diff --git a/Chickensoft.Introspection.Generator.Tests/test_cases/GlobalUsing.cs b/Chickensoft.Introspection.Generator.Tests/test_cases/GlobalUsing.cs index 1f2a3c9..eeecb09 100644 --- a/Chickensoft.Introspection.Generator.Tests/test_cases/GlobalUsing.cs +++ b/Chickensoft.Introspection.Generator.Tests/test_cases/GlobalUsing.cs @@ -1,6 +1,5 @@ #pragma warning disable IDE0005 // Using directive is unnecessary. global using MyExampleStruct = Chickensoft.Introspection.Generator.Tests.TestCases.ExampleStruct; -global using MyOutsideExampleStruct = - Chickensoft.Introspection.OutsideAssemblyForTests.ExampleStruct; +global using MyExampleType = int; #pragma warning restore IDE0005 // Using directive is unnecessary. diff --git a/Chickensoft.Introspection.Generator/Chickensoft.Introspection.Generator.csproj b/Chickensoft.Introspection.Generator/Chickensoft.Introspection.Generator.csproj index f0c214d..b0df518 100644 --- a/Chickensoft.Introspection.Generator/Chickensoft.Introspection.Generator.csproj +++ b/Chickensoft.Introspection.Generator/Chickensoft.Introspection.Generator.csproj @@ -43,7 +43,7 @@ - + diff --git a/Chickensoft.Introspection.Generator/src/TypeGenerator.cs b/Chickensoft.Introspection.Generator/src/TypeGenerator.cs index 3425a55..b39361f 100644 --- a/Chickensoft.Introspection.Generator/src/TypeGenerator.cs +++ b/Chickensoft.Introspection.Generator/src/TypeGenerator.cs @@ -494,7 +494,8 @@ TypeDeclarationSyntax type public static UsingDirective GetUsing(UsingDirectiveSyntax @using) => new( Alias: @using.Alias?.Name.NormalizeWhitespace().ToString(), - Name: @using.Name.NormalizeWhitespace().ToString(), + Name: @using.Name?.NormalizeWhitespace().ToString() + ?? @using.NamespaceOrType.NormalizeWhitespace().ToString(), IsGlobal: @using.GlobalKeyword is { ValueText: "global" }, IsStatic: @using.StaticKeyword is { ValueText: "static" }, IsAlias: @using.Alias != default diff --git a/Chickensoft.Introspection.OutsideAssemblyForTests/Chickensoft.Introspection.OutsideAssemblyForTests.csproj b/Chickensoft.Introspection.OutsideAssemblyForTests/Chickensoft.Introspection.OutsideAssemblyForTests.csproj deleted file mode 100644 index d35d8ff..0000000 --- a/Chickensoft.Introspection.OutsideAssemblyForTests/Chickensoft.Introspection.OutsideAssemblyForTests.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - net7.0 - disable - enable - - - diff --git a/Chickensoft.Introspection.OutsideAssemblyForTests/ExampleStruct.cs b/Chickensoft.Introspection.OutsideAssemblyForTests/ExampleStruct.cs deleted file mode 100644 index bcaeb91..0000000 --- a/Chickensoft.Introspection.OutsideAssemblyForTests/ExampleStruct.cs +++ /dev/null @@ -1,3 +0,0 @@ -namespace Chickensoft.Introspection.OutsideAssemblyForTests; - -public readonly record struct ExampleStruct;