Skip to content

Conversation

@GabCoolDude
Copy link
Contributor

@GabCoolDude GabCoolDude commented Nov 15, 2025

Closes godotengine/godot-proposals#8502

This PR allows read only properties and fields to be exported.

Example:

// All of these used to cause GD103, but now they work.
[Export] public readonly uint ReadonlyField = 999;
[Export] public Resource GetterOnlyProperty { get; } = new();
[Export] public Node ExpressionBody => GetNode("Node"); 

It works by adding PropertyUsage.ReadOnly and removing PropertyUsage.Storage to properties and fields that are marked as read only; PropertyUsage.Storage is removed because read-only properties and fields can only be declared in code, which makes storing them useless. The GD103 diagnostic has also been removed as it's no longer needed, documentation should also be updated to reflect this.

AFAIK exporting a read-only variable to godot should not cause any problems, and my testing has also proven this so far. This is the test project I've been using.

@GabCoolDude GabCoolDude requested a review from a team as a code owner November 15, 2025 21:44
@GabCoolDude
Copy link
Contributor Author

I see that the test for read-only exports in Godot.SourceGenerators.Tests is failing, obviously because the GD103 diagnostic is not produced anymore. Should I remove that test entirely then ? It seems to me that the only goal of that test was to see if the diagnostic was produced. I could add another test somewhere else too, but I don't see where exactly though...

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

C#: Allow read-only fields and properties to be export variables

2 participants