diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/GeneratedSources/ExportedFields_ScriptPropertyDefVal.generated.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/GeneratedSources/ExportedFields_ScriptPropertyDefVal.generated.cs index f201b7c8d8d..4caf51dc5a0 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/GeneratedSources/ExportedFields_ScriptPropertyDefVal.generated.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/GeneratedSources/ExportedFields_ScriptPropertyDefVal.generated.cs @@ -22,7 +22,7 @@ partial class ExportedFields values.Add(PropertyName.@_fieldInt16, global::Godot.Variant.From(___fieldInt16_default_value)); int ___fieldInt32_default_value = 10; values.Add(PropertyName.@_fieldInt32, global::Godot.Variant.From(___fieldInt32_default_value)); - long ___fieldInt64_default_value = 10; + long ___fieldInt64_default_value = -10_000; values.Add(PropertyName.@_fieldInt64, global::Godot.Variant.From(___fieldInt64_default_value)); byte ___fieldByte_default_value = 10; values.Add(PropertyName.@_fieldByte, global::Godot.Variant.From(___fieldByte_default_value)); diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/GeneratedSources/ExportedProperties_ScriptPropertyDefVal.generated.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/GeneratedSources/ExportedProperties_ScriptPropertyDefVal.generated.cs index ce154cad8e8..0bf0b0845a4 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/GeneratedSources/ExportedProperties_ScriptPropertyDefVal.generated.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/GeneratedSources/ExportedProperties_ScriptPropertyDefVal.generated.cs @@ -36,7 +36,7 @@ partial class ExportedProperties values.Add(PropertyName.@PropertyInt16, global::Godot.Variant.From(__PropertyInt16_default_value)); int __PropertyInt32_default_value = 10; values.Add(PropertyName.@PropertyInt32, global::Godot.Variant.From(__PropertyInt32_default_value)); - long __PropertyInt64_default_value = 10; + long __PropertyInt64_default_value = -10_000; values.Add(PropertyName.@PropertyInt64, global::Godot.Variant.From(__PropertyInt64_default_value)); byte __PropertyByte_default_value = 10; values.Add(PropertyName.@PropertyByte, global::Godot.Variant.From(__PropertyByte_default_value)); diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/Sources/ExportedFields.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/Sources/ExportedFields.cs index 0938d10afe5..07ae5cb6842 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/Sources/ExportedFields.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/Sources/ExportedFields.cs @@ -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; diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/Sources/ExportedProperties.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/Sources/ExportedProperties.cs index 9ae23066fc4..d7fcdc6b1b5 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/Sources/ExportedProperties.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators.Tests/TestData/Sources/ExportedProperties.cs @@ -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; diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertyDefValGenerator.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertyDefValGenerator.cs index fff32a10800..6c3824711f8 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertyDefValGenerator.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptPropertyDefValGenerator.cs @@ -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) {