Skip to content
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

[.NET] Interpolated strings as exported member's default value break source generation #88982

Closed
paulloz opened this issue Feb 28, 2024 · 0 comments · Fixed by #89007
Closed

Comments

@paulloz
Copy link
Member

paulloz commented Feb 28, 2024

Tested versions

  • Reproducible in: 4.3.dev [df78c06], 4.2.stable

System information

Windows 10

Issue description

Using an interpolated string as the default value for an exported field or property can lead to ScriptPropertyDefValGenerator producing invalid C# code. The generator fully qualifying identifiers within the interpolated string, leading to the following error during compilation. This is due to the use of global:: within the interpolation string. Identifiers would need to be enclosed ().

CS0103: The name 'global' does not exist in the current context ..._ScriptPropertyDefVal.generated.cs(...)

Steps to reproduce

  • Input script
public partial class Foo : Node
{
    [Export]
    public string EngineVersion = $"{Godot.Engine.GetVersionInfo()}";
}
  • Actual (-) vs. expected (+)
partial class Foo
{
#pragma warning disable CS0109 // Disable warning about redundant 'new' keyword
#if TOOLS
    /// <summary>
    /// Get the default values for all properties declared in this class.
    /// This method is used by Godot to determine the value that will be
    /// used by the inspector when resetting properties.
    /// Do not call this method.
    /// </summary>
    [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
    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>(1);
-        string __EngineVersion_default_value = $"{global::Godot.Engine.GetVersionInfo()}";
+        string __EngineVersion_default_value = $"{(global::Godot.Engine.GetVersionInfo())}";
        values.Add(PropertyName.EngineVersion, global::Godot.Variant.From<string>(__EngineVersion_default_value));
        return values;
    }
#endif // TOOLS
#pragma warning restore CS0109
}

Minimal reproduction project (MRP)

N/A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant