Merge pull request #112874 from AbsoluteMoose/def_val_generator_initializer_fix

Prevent C# source generators from fully qualifying members assigned to within an object initializer
This commit is contained in:
Rémi Verschelde 2025-12-01 11:48:40 +01:00
commit c3954a01aa
No known key found for this signature in database
GPG key ID: C3336907360768E1
7 changed files with 44 additions and 6 deletions

View file

@ -221,6 +221,10 @@ partial class ExportedFields
/// </summary> /// </summary>
public new static readonly global::Godot.StringName @_fieldGodotResourceTexture = "_fieldGodotResourceTexture"; public new static readonly global::Godot.StringName @_fieldGodotResourceTexture = "_fieldGodotResourceTexture";
/// <summary> /// <summary>
/// Cached name for the '_fieldGodotResourceTextureWithInitializer' field.
/// </summary>
public new static readonly global::Godot.StringName @_fieldGodotResourceTextureWithInitializer = "_fieldGodotResourceTextureWithInitializer";
/// <summary>
/// Cached name for the '_fieldStringName' field. /// Cached name for the '_fieldStringName' field.
/// </summary> /// </summary>
public new static readonly global::Godot.StringName @_fieldStringName = "_fieldStringName"; public new static readonly global::Godot.StringName @_fieldStringName = "_fieldStringName";
@ -469,6 +473,10 @@ partial class ExportedFields
this.@_fieldGodotResourceTexture = global::Godot.NativeInterop.VariantUtils.ConvertTo<global::Godot.Texture>(value); this.@_fieldGodotResourceTexture = global::Godot.NativeInterop.VariantUtils.ConvertTo<global::Godot.Texture>(value);
return true; return true;
} }
if (name == PropertyName.@_fieldGodotResourceTextureWithInitializer) {
this.@_fieldGodotResourceTextureWithInitializer = global::Godot.NativeInterop.VariantUtils.ConvertTo<global::Godot.Texture>(value);
return true;
}
if (name == PropertyName.@_fieldStringName) { if (name == PropertyName.@_fieldStringName) {
this.@_fieldStringName = global::Godot.NativeInterop.VariantUtils.ConvertTo<global::Godot.StringName>(value); this.@_fieldStringName = global::Godot.NativeInterop.VariantUtils.ConvertTo<global::Godot.StringName>(value);
return true; return true;
@ -719,6 +727,10 @@ partial class ExportedFields
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<global::Godot.Texture>(this.@_fieldGodotResourceTexture); value = global::Godot.NativeInterop.VariantUtils.CreateFrom<global::Godot.Texture>(this.@_fieldGodotResourceTexture);
return true; return true;
} }
if (name == PropertyName.@_fieldGodotResourceTextureWithInitializer) {
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<global::Godot.Texture>(this.@_fieldGodotResourceTextureWithInitializer);
return true;
}
if (name == PropertyName.@_fieldStringName) { if (name == PropertyName.@_fieldStringName) {
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<global::Godot.StringName>(this.@_fieldStringName); value = global::Godot.NativeInterop.VariantUtils.CreateFrom<global::Godot.StringName>(this.@_fieldStringName);
return true; return true;
@ -815,6 +827,7 @@ partial class ExportedFields
properties.Add(new(type: (global::Godot.Variant.Type)0, name: PropertyName.@_fieldVariant, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)135174, exported: true)); properties.Add(new(type: (global::Godot.Variant.Type)0, name: PropertyName.@_fieldVariant, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)135174, exported: true));
properties.Add(new(type: (global::Godot.Variant.Type)24, name: PropertyName.@_fieldGodotObjectOrDerived, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true)); properties.Add(new(type: (global::Godot.Variant.Type)24, name: PropertyName.@_fieldGodotObjectOrDerived, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));
properties.Add(new(type: (global::Godot.Variant.Type)24, name: PropertyName.@_fieldGodotResourceTexture, hint: (global::Godot.PropertyHint)17, hintString: "Texture", usage: (global::Godot.PropertyUsageFlags)4102, exported: true)); properties.Add(new(type: (global::Godot.Variant.Type)24, name: PropertyName.@_fieldGodotResourceTexture, hint: (global::Godot.PropertyHint)17, hintString: "Texture", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));
properties.Add(new(type: (global::Godot.Variant.Type)24, name: PropertyName.@_fieldGodotResourceTextureWithInitializer, hint: (global::Godot.PropertyHint)17, hintString: "Texture", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));
properties.Add(new(type: (global::Godot.Variant.Type)21, name: PropertyName.@_fieldStringName, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true)); properties.Add(new(type: (global::Godot.Variant.Type)21, name: PropertyName.@_fieldStringName, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));
properties.Add(new(type: (global::Godot.Variant.Type)22, name: PropertyName.@_fieldNodePath, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true)); properties.Add(new(type: (global::Godot.Variant.Type)22, name: PropertyName.@_fieldNodePath, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));
properties.Add(new(type: (global::Godot.Variant.Type)23, name: PropertyName.@_fieldRid, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true)); properties.Add(new(type: (global::Godot.Variant.Type)23, name: PropertyName.@_fieldRid, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));

View file

@ -11,7 +11,7 @@ partial class ExportedFields
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
internal new static global::System.Collections.Generic.Dictionary<global::Godot.StringName, global::Godot.Variant> GetGodotPropertyDefaultValues() internal new static global::System.Collections.Generic.Dictionary<global::Godot.StringName, global::Godot.Variant> GetGodotPropertyDefaultValues()
{ {
var values = new global::System.Collections.Generic.Dictionary<global::Godot.StringName, global::Godot.Variant>(61); var values = new global::System.Collections.Generic.Dictionary<global::Godot.StringName, global::Godot.Variant>(62);
bool ___fieldBoolean_default_value = true; bool ___fieldBoolean_default_value = true;
values.Add(PropertyName.@_fieldBoolean, global::Godot.Variant.From<bool>(___fieldBoolean_default_value)); values.Add(PropertyName.@_fieldBoolean, global::Godot.Variant.From<bool>(___fieldBoolean_default_value));
char ___fieldChar_default_value = 'f'; char ___fieldChar_default_value = 'f';
@ -118,6 +118,8 @@ partial class ExportedFields
values.Add(PropertyName.@_fieldGodotObjectOrDerived, global::Godot.Variant.From<global::Godot.GodotObject>(___fieldGodotObjectOrDerived_default_value)); values.Add(PropertyName.@_fieldGodotObjectOrDerived, global::Godot.Variant.From<global::Godot.GodotObject>(___fieldGodotObjectOrDerived_default_value));
global::Godot.Texture ___fieldGodotResourceTexture_default_value = default; global::Godot.Texture ___fieldGodotResourceTexture_default_value = default;
values.Add(PropertyName.@_fieldGodotResourceTexture, global::Godot.Variant.From<global::Godot.Texture>(___fieldGodotResourceTexture_default_value)); values.Add(PropertyName.@_fieldGodotResourceTexture, global::Godot.Variant.From<global::Godot.Texture>(___fieldGodotResourceTexture_default_value));
global::Godot.Texture ___fieldGodotResourceTextureWithInitializer_default_value = new() { ResourceName = "" };
values.Add(PropertyName.@_fieldGodotResourceTextureWithInitializer, global::Godot.Variant.From<global::Godot.Texture>(___fieldGodotResourceTextureWithInitializer_default_value));
global::Godot.StringName ___fieldStringName_default_value = new global::Godot.StringName("foo"); global::Godot.StringName ___fieldStringName_default_value = new global::Godot.StringName("foo");
values.Add(PropertyName.@_fieldStringName, global::Godot.Variant.From<global::Godot.StringName>(___fieldStringName_default_value)); values.Add(PropertyName.@_fieldStringName, global::Godot.Variant.From<global::Godot.StringName>(___fieldStringName_default_value));
global::Godot.NodePath ___fieldNodePath_default_value = new global::Godot.NodePath("foo"); global::Godot.NodePath ___fieldNodePath_default_value = new global::Godot.NodePath("foo");

View file

@ -261,6 +261,10 @@ partial class ExportedProperties
/// </summary> /// </summary>
public new static readonly global::Godot.StringName @PropertyGodotResourceTexture = "PropertyGodotResourceTexture"; public new static readonly global::Godot.StringName @PropertyGodotResourceTexture = "PropertyGodotResourceTexture";
/// <summary> /// <summary>
/// Cached name for the 'PropertyGodotResourceTextureWithInitializer' property.
/// </summary>
public new static readonly global::Godot.StringName @PropertyGodotResourceTextureWithInitializer = "PropertyGodotResourceTextureWithInitializer";
/// <summary>
/// Cached name for the 'PropertyStringName' property. /// Cached name for the 'PropertyStringName' property.
/// </summary> /// </summary>
public new static readonly global::Godot.StringName @PropertyStringName = "PropertyStringName"; public new static readonly global::Godot.StringName @PropertyStringName = "PropertyStringName";
@ -573,6 +577,10 @@ partial class ExportedProperties
this.@PropertyGodotResourceTexture = global::Godot.NativeInterop.VariantUtils.ConvertTo<global::Godot.Texture>(value); this.@PropertyGodotResourceTexture = global::Godot.NativeInterop.VariantUtils.ConvertTo<global::Godot.Texture>(value);
return true; return true;
} }
if (name == PropertyName.@PropertyGodotResourceTextureWithInitializer) {
this.@PropertyGodotResourceTextureWithInitializer = global::Godot.NativeInterop.VariantUtils.ConvertTo<global::Godot.Texture>(value);
return true;
}
if (name == PropertyName.@PropertyStringName) { if (name == PropertyName.@PropertyStringName) {
this.@PropertyStringName = global::Godot.NativeInterop.VariantUtils.ConvertTo<global::Godot.StringName>(value); this.@PropertyStringName = global::Godot.NativeInterop.VariantUtils.ConvertTo<global::Godot.StringName>(value);
return true; return true;
@ -887,6 +895,10 @@ partial class ExportedProperties
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<global::Godot.Texture>(this.@PropertyGodotResourceTexture); value = global::Godot.NativeInterop.VariantUtils.CreateFrom<global::Godot.Texture>(this.@PropertyGodotResourceTexture);
return true; return true;
} }
if (name == PropertyName.@PropertyGodotResourceTextureWithInitializer) {
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<global::Godot.Texture>(this.@PropertyGodotResourceTextureWithInitializer);
return true;
}
if (name == PropertyName.@PropertyStringName) { if (name == PropertyName.@PropertyStringName) {
value = global::Godot.NativeInterop.VariantUtils.CreateFrom<global::Godot.StringName>(this.@PropertyStringName); value = global::Godot.NativeInterop.VariantUtils.CreateFrom<global::Godot.StringName>(this.@PropertyStringName);
return true; return true;
@ -1024,6 +1036,7 @@ partial class ExportedProperties
properties.Add(new(type: (global::Godot.Variant.Type)0, name: PropertyName.@PropertyVariant, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)135174, exported: true)); properties.Add(new(type: (global::Godot.Variant.Type)0, name: PropertyName.@PropertyVariant, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)135174, exported: true));
properties.Add(new(type: (global::Godot.Variant.Type)24, name: PropertyName.@PropertyGodotObjectOrDerived, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true)); properties.Add(new(type: (global::Godot.Variant.Type)24, name: PropertyName.@PropertyGodotObjectOrDerived, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));
properties.Add(new(type: (global::Godot.Variant.Type)24, name: PropertyName.@PropertyGodotResourceTexture, hint: (global::Godot.PropertyHint)17, hintString: "Texture", usage: (global::Godot.PropertyUsageFlags)4102, exported: true)); properties.Add(new(type: (global::Godot.Variant.Type)24, name: PropertyName.@PropertyGodotResourceTexture, hint: (global::Godot.PropertyHint)17, hintString: "Texture", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));
properties.Add(new(type: (global::Godot.Variant.Type)24, name: PropertyName.@PropertyGodotResourceTextureWithInitializer, hint: (global::Godot.PropertyHint)17, hintString: "Texture", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));
properties.Add(new(type: (global::Godot.Variant.Type)21, name: PropertyName.@PropertyStringName, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true)); properties.Add(new(type: (global::Godot.Variant.Type)21, name: PropertyName.@PropertyStringName, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));
properties.Add(new(type: (global::Godot.Variant.Type)22, name: PropertyName.@PropertyNodePath, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true)); properties.Add(new(type: (global::Godot.Variant.Type)22, name: PropertyName.@PropertyNodePath, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));
properties.Add(new(type: (global::Godot.Variant.Type)23, name: PropertyName.@PropertyRid, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true)); properties.Add(new(type: (global::Godot.Variant.Type)23, name: PropertyName.@PropertyRid, hint: (global::Godot.PropertyHint)0, hintString: "", usage: (global::Godot.PropertyUsageFlags)4102, exported: true));

View file

@ -11,7 +11,7 @@ partial class ExportedProperties
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)] [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
internal new static global::System.Collections.Generic.Dictionary<global::Godot.StringName, global::Godot.Variant> GetGodotPropertyDefaultValues() internal new static global::System.Collections.Generic.Dictionary<global::Godot.StringName, global::Godot.Variant> GetGodotPropertyDefaultValues()
{ {
var values = new global::System.Collections.Generic.Dictionary<global::Godot.StringName, global::Godot.Variant>(70); var values = new global::System.Collections.Generic.Dictionary<global::Godot.StringName, global::Godot.Variant>(71);
string __NotGenerateComplexLamdaProperty_default_value = default; string __NotGenerateComplexLamdaProperty_default_value = default;
values.Add(PropertyName.@NotGenerateComplexLamdaProperty, global::Godot.Variant.From<string>(__NotGenerateComplexLamdaProperty_default_value)); values.Add(PropertyName.@NotGenerateComplexLamdaProperty, global::Godot.Variant.From<string>(__NotGenerateComplexLamdaProperty_default_value));
string __NotGenerateLamdaNoFieldProperty_default_value = default; string __NotGenerateLamdaNoFieldProperty_default_value = default;
@ -138,6 +138,8 @@ partial class ExportedProperties
values.Add(PropertyName.@PropertyGodotObjectOrDerived, global::Godot.Variant.From<global::Godot.GodotObject>(__PropertyGodotObjectOrDerived_default_value)); values.Add(PropertyName.@PropertyGodotObjectOrDerived, global::Godot.Variant.From<global::Godot.GodotObject>(__PropertyGodotObjectOrDerived_default_value));
global::Godot.Texture __PropertyGodotResourceTexture_default_value = default; global::Godot.Texture __PropertyGodotResourceTexture_default_value = default;
values.Add(PropertyName.@PropertyGodotResourceTexture, global::Godot.Variant.From<global::Godot.Texture>(__PropertyGodotResourceTexture_default_value)); values.Add(PropertyName.@PropertyGodotResourceTexture, global::Godot.Variant.From<global::Godot.Texture>(__PropertyGodotResourceTexture_default_value));
global::Godot.Texture __PropertyGodotResourceTextureWithInitializer_default_value = new() { ResourceName = "" };
values.Add(PropertyName.@PropertyGodotResourceTextureWithInitializer, global::Godot.Variant.From<global::Godot.Texture>(__PropertyGodotResourceTextureWithInitializer_default_value));
global::Godot.StringName __PropertyStringName_default_value = new global::Godot.StringName("foo"); global::Godot.StringName __PropertyStringName_default_value = new global::Godot.StringName("foo");
values.Add(PropertyName.@PropertyStringName, global::Godot.Variant.From<global::Godot.StringName>(__PropertyStringName_default_value)); values.Add(PropertyName.@PropertyStringName, global::Godot.Variant.From<global::Godot.StringName>(__PropertyStringName_default_value));
global::Godot.NodePath __PropertyNodePath_default_value = new global::Godot.NodePath("foo"); global::Godot.NodePath __PropertyNodePath_default_value = new global::Godot.NodePath("foo");

View file

@ -88,6 +88,7 @@ public partial class ExportedFields : GodotObject
// Classes // Classes
[Export] private GodotObject _fieldGodotObjectOrDerived; [Export] private GodotObject _fieldGodotObjectOrDerived;
[Export] private Godot.Texture _fieldGodotResourceTexture; [Export] private Godot.Texture _fieldGodotResourceTexture;
[Export] private Godot.Texture _fieldGodotResourceTextureWithInitializer = new() { ResourceName = "" };
[Export] private StringName _fieldStringName = new StringName("foo"); [Export] private StringName _fieldStringName = new StringName("foo");
[Export] private NodePath _fieldNodePath = new NodePath("foo"); [Export] private NodePath _fieldNodePath = new NodePath("foo");
[Export] private Rid _fieldRid; [Export] private Rid _fieldRid;

View file

@ -207,6 +207,7 @@ public partial class ExportedProperties(string primaryCtorParameter) : GodotObje
// Classes // Classes
[Export] private GodotObject PropertyGodotObjectOrDerived { get; set; } [Export] private GodotObject PropertyGodotObjectOrDerived { get; set; }
[Export] private Godot.Texture PropertyGodotResourceTexture { get; set; } [Export] private Godot.Texture PropertyGodotResourceTexture { get; set; }
[Export] private Godot.Texture PropertyGodotResourceTextureWithInitializer { get; set; } = new() { ResourceName = "" };
[Export] private StringName PropertyStringName { get; set; } = new StringName("foo"); [Export] private StringName PropertyStringName { get; set; } = new StringName("foo");
[Export] private NodePath PropertyNodePath { get; set; } = new NodePath("foo"); [Export] private NodePath PropertyNodePath { get; set; } = new NodePath("foo");
[Export] private Rid PropertyRid { get; set; } [Export] private Rid PropertyRid { get; set; }

View file

@ -212,11 +212,17 @@ namespace Godot.SourceGenerators
private static void FullQualifiedSyntax(SyntaxNode node, SemanticModel sm, StringBuilder sb, bool isFirstNode) private static void FullQualifiedSyntax(SyntaxNode node, SemanticModel sm, StringBuilder sb, bool isFirstNode)
{ {
if (node is NameSyntax ns && (isFirstNode || node.Parent is not MemberAccessExpressionSyntax)) if (node is NameSyntax ns)
{ {
SymbolInfo nameInfo = sm.GetSymbolInfo(ns); bool isMemberAccess = !isFirstNode && node.Parent is MemberAccessExpressionSyntax;
sb.Append(nameInfo.Symbol?.ToDisplayString(FullyQualifiedFormatIncludeGlobal) ?? ns.ToString()); bool isInitializer = isFirstNode && node.Parent is AssignmentExpressionSyntax { Parent: InitializerExpressionSyntax };
return;
if (!isMemberAccess && !isInitializer)
{
SymbolInfo nameInfo = sm.GetSymbolInfo(ns);
sb.Append(nameInfo.Symbol?.ToDisplayString(FullyQualifiedFormatIncludeGlobal) ?? ns.ToString());
return;
}
} }
bool innerIsFirstNode = true; bool innerIsFirstNode = true;