Fix extraction of C# default property values when negative

This commit is contained in:
Paul Joannon 2025-04-13 17:57:20 +02:00
parent 215acd52e8
commit 88191b0b15
No known key found for this signature in database
GPG key ID: C12F69B0AD0390DD
5 changed files with 11 additions and 4 deletions

View file

@ -22,7 +22,7 @@ partial class ExportedFields
values.Add(PropertyName.@_fieldInt16, global::Godot.Variant.From<short>(___fieldInt16_default_value));
int ___fieldInt32_default_value = 10;
values.Add(PropertyName.@_fieldInt32, global::Godot.Variant.From<int>(___fieldInt32_default_value));
long ___fieldInt64_default_value = 10;
long ___fieldInt64_default_value = -10_000;
values.Add(PropertyName.@_fieldInt64, global::Godot.Variant.From<long>(___fieldInt64_default_value));
byte ___fieldByte_default_value = 10;
values.Add(PropertyName.@_fieldByte, global::Godot.Variant.From<byte>(___fieldByte_default_value));

View file

@ -36,7 +36,7 @@ partial class ExportedProperties
values.Add(PropertyName.@PropertyInt16, global::Godot.Variant.From<short>(__PropertyInt16_default_value));
int __PropertyInt32_default_value = 10;
values.Add(PropertyName.@PropertyInt32, global::Godot.Variant.From<int>(__PropertyInt32_default_value));
long __PropertyInt64_default_value = 10;
long __PropertyInt64_default_value = -10_000;
values.Add(PropertyName.@PropertyInt64, global::Godot.Variant.From<long>(__PropertyInt64_default_value));
byte __PropertyByte_default_value = 10;
values.Add(PropertyName.@PropertyByte, global::Godot.Variant.From<byte>(__PropertyByte_default_value));

View file

@ -9,7 +9,7 @@ public partial class ExportedFields : GodotObject
[Export] private SByte _fieldSByte = 10;
[Export] private Int16 _fieldInt16 = 10;
[Export] private Int32 _fieldInt32 = 10;
[Export] private Int64 _fieldInt64 = 10;
[Export] private Int64 _fieldInt64 = -10_000;
[Export] private Byte _fieldByte = 10;
[Export] private UInt16 _fieldUInt16 = 10;
[Export] private UInt32 _fieldUInt32 = 10;

View file

@ -97,7 +97,7 @@ public partial class ExportedProperties : GodotObject
[Export] private SByte PropertySByte { get; set; } = 10;
[Export] private Int16 PropertyInt16 { get; set; } = 10;
[Export] private Int32 PropertyInt32 { get; set; } = 10;
[Export] private Int64 PropertyInt64 { get; set; } = 10;
[Export] private Int64 PropertyInt64 { get; set; } = -10_000;
[Export] private Byte PropertyByte { get; set; } = 10;
[Export] private UInt16 PropertyUInt16 { get; set; } = 10;
[Export] private UInt32 PropertyUInt32 { get; set; } = 10;

View file

@ -430,6 +430,13 @@ namespace Godot.SourceGenerators
return true;
}
// Handle negative literals (e.g., `-10`)
if (expression is PrefixUnaryExpressionSyntax { Operand: LiteralExpressionSyntax } &&
expression.Kind() == SyntaxKind.UnaryMinusExpression)
{
return true;
}
// Handle identifiers (e.g., variable names)
if (expression is IdentifierNameSyntax identifier)
{