Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
fix: nullable reference types in static reflection tables (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
jolexxa authored Oct 16, 2023
1 parent 83fc7b9 commit 64526be
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace NullableReferenceTypeMember;

using Godot;
using SuperNodes.Types;

[SuperNode(typeof(MyPowerUp))]
public partial class ExampleNode : Node {
public override partial void _Notification(int what);
}

public class MyObject { }


[PowerUp]
public partial class MyPowerUp : Node {
public MyObject? SomeObj { get; set; }
}
17 changes: 16 additions & 1 deletion SuperNodes.Tests/tests/common/services/CodeServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ public class Bar : IFoo, IBar {
protected readonly int _field2 = 1;
public string? NullableProperty { get; set; }
public void Method() {}
}
Expand Down Expand Up @@ -303,6 +305,19 @@ public interface IBar {
new SimpleSymbolDisplayPart(SymbolDisplayPartKind.Keyword, "bool")
)
),
new PropOrField(
Name: "NullableProperty",
Reference: "NullableProperty",
Type: "string",
Attributes: ImmutableArray<AttributeDescription>.Empty,
IsField: false,
IsMutable: true,
IsReadable: true,
NameParts: ImmutableArray<SimpleSymbolDisplayPart>.Empty,
TypeParts: ImmutableArray.Create(
new SimpleSymbolDisplayPart(SymbolDisplayPartKind.Keyword, "string")
)
),
new PropOrField(
Name: "Property",
Reference: "Property",
Expand All @@ -323,7 +338,7 @@ public interface IBar {
TypeParts: ImmutableArray.Create(
new SimpleSymbolDisplayPart(SymbolDisplayPartKind.Keyword, "string")
)
),
)
}.ToImmutableArray();

result.ShouldDeepEqual(expected);
Expand Down
2 changes: 1 addition & 1 deletion SuperNodes.Types/Chickensoft.SuperNodes.Types.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<DebugType>portable</DebugType>

<Title>SuperNodes Types</Title>
<Version>1.6.0</Version>
<Version>1.6.1</Version>
<Description>Runtime types for SuperNodes.</Description>
<Copyright>© 2023 Chickensoft</Copyright>
<Authors>Chickensoft</Authors>
Expand Down
2 changes: 1 addition & 1 deletion SuperNodes/Chickensoft.SuperNodes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<NoWarn>NU5128</NoWarn>

<Title>SuperNodes</Title>
<Version>1.6.0</Version>
<Version>1.6.1</Version>
<Description>Supercharge your Godot nodes with lifecycle-aware mixins, third party source generators, script introspection, and dynamic property manipulation — all without runtime reflection!</Description>
<Copyright>© 2023 Chickensoft Games</Copyright>
<Authors>Chickensoft</Authors>
Expand Down
6 changes: 6 additions & 0 deletions SuperNodes/src/common/services/CodeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,12 @@ member is IPropertySymbol property
isMutable = !field.IsReadOnly;
}

// Remove any trailing ? part from typeParts — we don't need to worry
// about overall nullability.
if (typeParts.Length > 0 && typeParts.Last().Value == "?") {
typeParts = typeParts.RemoveAt(typeParts.Length - 1);
}

var attributes = GetAttributesForPropOrField(rawAttributes);

var propOrField = new PropOrField(
Expand Down

0 comments on commit 64526be

Please sign in to comment.