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

C#: Script Generator fails when using generics in a dictionary. #99454

Closed
paulcnova opened this issue Nov 20, 2024 · 1 comment · Fixed by #99485
Closed

C#: Script Generator fails when using generics in a dictionary. #99454

paulcnova opened this issue Nov 20, 2024 · 1 comment · Fixed by #99485

Comments

@paulcnova
Copy link

Tested versions

  • Reproducible in: 4.4.dev4, 4.4.dev3, 4.4.dev2
  • Not reproducible in: 4.3.stable, 4.4.dev1

System information

Godot v4.4.dev4.mono - Windows 10.0.22631 - Multi-window, 1 monitor - Vulkan (Forward+) - integrated Intel(R) Iris(R) Xe Graphics (Intel Corporation; 31.0.101.4314) - 13th Gen Intel(R) Core(TM) i7-1360P (16 threads)

Issue description

I migrated a project over to 4.4.dev4 when the project was using 4.3.stable. It fail compilation and gave this error:

CS8785: Generator 'ScriptPropertiesGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'InvalidOperationException' with message 'Nullable object must have a value.' CSC(0,0)

I narrowed it down to a single property from a single C# file. It seems the script generator is having trouble with generics in dictionaries. The following code created the failure in compilation:

public partial class SpatialHashMap<[MustBeVariant] T> : Resource
{
    [Export] public Dictionary<Vector3I, T> Data { get; set; }
}

Steps to reproduce

  1. Create a new .cs file
  2. Add the code below into that file:
using Godot;
using Godot.Collections;

public partial class SpatialHashMap<[MustBeVariant] T> : Resource
{
    [Export] public Dictionary<Vector3I, T> Data { get; set; } = new Dictionary<Vector3I, T>();
}
  1. Build

Minimal reproduction project (MRP)

N/A

@raulsntos
Copy link
Member

Unbound generics are not supported in exported properties, this applies to every generic type (like Godot.Collections.Array<T>). However, Godot didn't support type hints for Dictionaries until 4.4 so that's why you are only running into this now. Before 4.4 we were exporting untyped Dictionaries in these cases, but now we try to generate the proper type hints and since the type is unbound we can't.

Related:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Release Blocker
Development

Successfully merging a pull request may close this issue.

2 participants