Skip to content

fix: edge cases #10

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

Merged
merged 1 commit into from
Sep 17, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
OpenType: typeof(string),
ClosedType: typeof(string),
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: receiver => receiver.Receive<string>(),
GenericTypeGetter: static receiver => receiver.Receive<string>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
OpenType: typeof(string),
ClosedType: typeof(string),
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: receiver => receiver.Receive<string>(),
GenericTypeGetter: static receiver => receiver.Receive<string>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
OpenType: typeof(string),
ClosedType: typeof(string),
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: receiver => receiver.Receive<string>(),
GenericTypeGetter: static receiver => receiver.Receive<string>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
OpenType: typeof(int),
ClosedType: typeof(int),
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: receiver => receiver.Receive<int>(),
GenericTypeGetter: static receiver => receiver.Receive<int>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
Expand All @@ -52,7 +52,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
OpenType: typeof(string),
ClosedType: typeof(string),
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: receiver => receiver.Receive<string>(),
GenericTypeGetter: static receiver => receiver.Receive<string>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
OpenType: typeof(string),
ClosedType: typeof(string),
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: receiver => receiver.Receive<string>(),
GenericTypeGetter: static receiver => receiver.Receive<string>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
OpenType: typeof(string),
ClosedType: typeof(string),
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: receiver => receiver.Receive<string>(),
GenericTypeGetter: static receiver => receiver.Receive<string>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
OpenType: typeof(string),
ClosedType: typeof(string),
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: receiver => receiver.Receive<string>(),
GenericTypeGetter: static receiver => receiver.Receive<string>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
Expand All @@ -59,7 +59,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
OpenType: typeof(int),
ClosedType: typeof(int),
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: receiver => receiver.Receive<int>(),
GenericTypeGetter: static receiver => receiver.Receive<int>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
Expand All @@ -80,11 +80,11 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
OpenType: typeof(float),
ClosedType: typeof(float),
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: receiver => receiver.Receive<float>(),
GenericTypeGetter: static receiver => receiver.Receive<float>(),
GenericTypeGetter2: default
)
},
GenericTypeGetter: receiver => receiver.Receive<Nullable<float>>(),
GenericTypeGetter: static receiver => receiver.Receive<Nullable<float>>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
Expand All @@ -104,7 +104,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
OpenType: typeof(int),
ClosedType: typeof(int),
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: receiver => receiver.Receive<int>(),
GenericTypeGetter: static receiver => receiver.Receive<int>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
OpenType: typeof(string),
ClosedType: typeof(string),
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: receiver => receiver.Receive<string>(),
GenericTypeGetter: static receiver => receiver.Receive<string>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
OpenType: typeof(string),
ClosedType: typeof(string),
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: receiver => receiver.Receive<string>(),
GenericTypeGetter: static receiver => receiver.Receive<string>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
Expand All @@ -51,7 +51,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
OpenType: typeof(int),
ClosedType: typeof(int),
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: receiver => receiver.Receive<int>(),
GenericTypeGetter: static receiver => receiver.Receive<int>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
Expand All @@ -71,7 +71,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
OpenType: typeof(string),
ClosedType: typeof(string),
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: receiver => receiver.Receive<string>(),
GenericTypeGetter: static receiver => receiver.Receive<string>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
Expand All @@ -91,7 +91,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
OpenType: typeof(InitArgsEnum),
ClosedType: typeof(InitArgsEnum),
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: receiver => receiver.Receive<InitArgsEnum>(),
GenericTypeGetter: static receiver => receiver.Receive<InitArgsEnum>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
Expand All @@ -111,7 +111,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
OpenType: typeof(InitArgsEnum),
ClosedType: typeof(InitArgsEnum),
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: receiver => receiver.Receive<InitArgsEnum>(),
GenericTypeGetter: static receiver => receiver.Receive<InitArgsEnum>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
Expand All @@ -131,7 +131,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
OpenType: typeof(string),
ClosedType: typeof(string),
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: receiver => receiver.Receive<string>(),
GenericTypeGetter: static receiver => receiver.Receive<string>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
OpenType: typeof(string),
ClosedType: typeof(string),
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: receiver => receiver.Receive<string>(),
GenericTypeGetter: static receiver => receiver.Receive<string>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
OpenType: typeof(string),
ClosedType: typeof(string),
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: receiver => receiver.Receive<string>(),
GenericTypeGetter: static receiver => receiver.Receive<string>(),
GenericTypeGetter2: default
)
},
GenericTypeGetter: receiver => receiver.Receive<List<string>>(),
GenericTypeGetter: static receiver => receiver.Receive<List<string>>(),
GenericTypeGetter2: default
),
new GenericType(
Expand All @@ -58,20 +58,20 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
OpenType: typeof(int),
ClosedType: typeof(int),
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: receiver => receiver.Receive<int>(),
GenericTypeGetter: static receiver => receiver.Receive<int>(),
GenericTypeGetter2: default
)
},
GenericTypeGetter: receiver => receiver.Receive<List<int>>(),
GenericTypeGetter: static receiver => receiver.Receive<List<int>>(),
GenericTypeGetter2: default
)
},
GenericTypeGetter: receiver => receiver.Receive<List<List<int>>>(),
GenericTypeGetter: static receiver => receiver.Receive<List<List<int>>>(),
GenericTypeGetter2: default
)
},
GenericTypeGetter: receiver => receiver.Receive<Dictionary<List<string>, List<List<int>>>>(),
GenericTypeGetter2: receiver => receiver.Receive<List<string>, List<List<int>>>()
GenericTypeGetter: static receiver => receiver.Receive<Dictionary<List<string>, List<List<int>>>>(),
GenericTypeGetter2: static receiver => receiver.Receive<List<string>, List<List<int>>>()
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
[typeof(TagAttribute)] = new System.Attribute[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
OpenType: typeof(int),
ClosedType: typeof(int),
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: receiver => receiver.Receive<int>(),
GenericTypeGetter: static receiver => receiver.Receive<int>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
OpenType: typeof(int),
ClosedType: typeof(int),
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: receiver => receiver.Receive<int>(),
GenericTypeGetter: static receiver => receiver.Receive<int>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
Expand All @@ -51,7 +51,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
OpenType: typeof(string),
ClosedType: typeof(string),
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: receiver => receiver.Receive<string>(),
GenericTypeGetter: static receiver => receiver.Receive<string>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
OpenType: typeof(string),
ClosedType: typeof(string),
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: receiver => receiver.Receive<string>(),
GenericTypeGetter: static receiver => receiver.Receive<string>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
Expand All @@ -63,7 +63,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
OpenType: typeof(float),
ClosedType: typeof(float),
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: receiver => receiver.Receive<float>(),
GenericTypeGetter: static receiver => receiver.Receive<float>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
Expand All @@ -83,7 +83,7 @@ public class MetatypeMetadata : Chickensoft.Introspection.IMetatype {
OpenType: typeof(int),
ClosedType: typeof(int),
Arguments: System.Array.Empty<GenericType>(),
GenericTypeGetter: receiver => receiver.Receive<int>(),
GenericTypeGetter: static receiver => receiver.Receive<int>(),
GenericTypeGetter2: default
),
Attributes: new System.Collections.Generic.Dictionary<System.Type, System.Attribute[]>() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Chickensoft.Introspection.Generator.Tests.TestCases;

using System.IO;
using Result = (int, string);

public static class UsingAmbiguity {
// make sure tuple aliases don't interfere with using imports
public static Result DoSomething() => (1, "Hello");

public static void DoSomethingWithADisposable() {
// make sure using statements don't interfere with using imports
using var stream = new MemoryStream();
}
}
11 changes: 10 additions & 1 deletion Chickensoft.Introspection.Generator/src/TypeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context) {
typeA.MergePartialDefinition(typeB)
)
)
.Where(type => type.Kind != DeclaredTypeKind.Error)
.OrderBy(type => type.FullNameOpen);

var uniqueTypes = uniqueTypeList.ToDictionary(
Expand Down Expand Up @@ -479,7 +480,15 @@ TypeDeclarationSyntax type
allUsings = allUsings.AddRange(comp.Usings);
}
}
return allUsings.Select(GetUsing).ToImmutableHashSet();
return allUsings
// `Name` will be null if used as an alias for a tuple (unrelated to
// the using import directive).
//
// Note that we don't have access to the NamespaceOrType property
// introduced after Microsoft.CodeAnalysis.CSharp v4.4.0 which would
// reference the tuple aliasing.
.Where(@using => @using.Name is not null)
.Select(GetUsing).ToImmutableHashSet();
}

public static UsingDirective GetUsing(UsingDirectiveSyntax @using) =>
Expand Down
27 changes: 26 additions & 1 deletion Chickensoft.Introspection.Generator/src/models/DeclaredType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ DeclaredType declaredType
Location: Location,
BaseType: BaseType,
Usings: Usings.Union(declaredType.Usings),
Kind: Kind,
Kind: PickDeclaredTypeKind(Kind, declaredType.Kind),
IsStatic: PickIsStatic(declaredType.IsStatic),
IsPublicOrInternal: PickIsPublicOrInternal(declaredType.IsPublicOrInternal),
Properties
Expand All @@ -257,6 +257,31 @@ DeclaredType declaredType
internal Location PickSyntaxLocation(Location other) =>
HasIntrospectiveAttribute ? SyntaxLocation : other;

internal static DeclaredTypeKind PickDeclaredTypeKind(
DeclaredTypeKind kind,
DeclaredTypeKind other
) => kind switch {
// both are the same — no change
_ when other == kind => kind,

// abstract + concrete = abstract
DeclaredTypeKind.AbstractType when other is DeclaredTypeKind.ConcreteType
=> DeclaredTypeKind.AbstractType,
DeclaredTypeKind.ConcreteType when other is DeclaredTypeKind.AbstractType
=> DeclaredTypeKind.AbstractType,
// ---

// static + concrete = static
DeclaredTypeKind.StaticClass when other is DeclaredTypeKind.ConcreteType
=> DeclaredTypeKind.StaticClass,
DeclaredTypeKind.ConcreteType when other is DeclaredTypeKind.StaticClass
=> DeclaredTypeKind.StaticClass,
// ---

// no other combinations have valid results
_ => DeclaredTypeKind.Error
};

internal bool PickIsStatic(bool other) => IsStatic || other;

internal bool PickIsPublicOrInternal(bool other) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ public enum DeclaredTypeKind {
StaticClass,
AbstractType,
ConcreteType,
Interface
Interface,
Error
}
4 changes: 2 additions & 2 deletions Chickensoft.Introspection/src/types/IIntrospective.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public interface IIntrospective {
/// Invokes the handler of each mixin that is applied to the type.
/// </summary>
public void InvokeMixins() {
foreach (var mixin in Metatype.Mixins) {
Metatype.MixinHandlers[mixin](this);
for (var i = 0; i < Metatype.Mixins.Count; i++) {
Metatype.MixinHandlers[Metatype.Mixins[i]](this);
}
}

Expand Down
Loading