Skip to content

Reflection_Engine: Fix errors when handling constraints on generics - #3636

Open
adecler wants to merge 5 commits into
developfrom
Reflection_Engine-#3614-StructConstrainOnGenerics
Open

adecler wants to merge 5 commits into
developfrom
Reflection_Engine-#3614-StructConstrainOnGenerics

Conversation

@adecler

@adecler adecler commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Issues addressed by this PR

Closes #3614

  • Fixes the generic case shown in the issue as well as a few others that could happen in the future.
  • It also refactors some of the code since it was a bit messy with quite a bit of duplication.
  • Added unit tests using Claude.
  • Finally, I also fixed an infinite loop issue in the serialiser that was highlighted by the GH script below.

Test files

The simplest to compare the before and after is to run this GH script:
GenericMethodSerialisation.zip
First, it serialises all existing generic BHoM methods to establish a baseline (serialisation relies heavily on reflection so it is a good way to cover many cases at once).
Secondly, it test a set of weird generic cases. It's quite likely that we will never encounter most of them. But, since issue #3614 is also related to a case we don't have in the installer, it's best to be prepared.

You can also run the new unit tests added in this PR.

@adecler adecler self-assigned this Nov 9, 2026
@adecler adecler added the type:bug Error or unexpected behaviour label Nov 9, 2026
@adecler

adecler commented Nov 9, 2026

Copy link
Copy Markdown
Member Author

@BHoMBot check code-compliance

@bhombot-ci

bhombot-ci Bot commented Nov 9, 2026

Copy link
Copy Markdown

@adecler to confirm, the following actions are now queued:

  • check code-compliance

There are 578 requests in the queue ahead of you.

@IsakNaslundBh IsakNaslundBh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have tested this through, and seem the back and forward to json is functioning. However the methods are not triggering correctly in the UI.

For example, this method:

            public static T FailingGenericMethod<T>(this T val) where T : struct
            {
                return default(T);
            }

Get stuck to double, and can never accept anything else:

image

Also tried some other examples, that might be out of scope for this, like:

        public static double MassTest<T>(this T elementM) where T : BHoMObject, IElementM

Does not work at all (think it is under the "unsatisfied" case.

Also tried a case I at one point actually wanted to make use of, with the new() keyword:

        public static ILink<TNode> SetElements0D<TNode>(this ILink<TNode> link, List<IElement0D> newElements0D)
            where TNode : INode, new()

To allow to skip the Activator.CreateInstance call. This is ofc of less criticality in general, and might be out of scope of this PR.

Mostly wanted to flag that I am not sure if the fixes in here actually makes the methods work in the UI (as shown by the double case).

Will leave this as a comment rather than blocking request for changes.

@adecler

adecler commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

@IsakNaslundBh , yes this PR is just to address the issue raised by Peter since it was impacting other components. The handling of generics in the UI is a separate issue that will likely have to be addressed in BHoM_UI. Although it will be tricky since we don't know what the method should be until something is plugged in the input.

@adecler

adecler commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

@BHoMBot check documentation-compliance

@bhombot-ci

bhombot-ci Bot commented Dec 1, 2026

Copy link
Copy Markdown

@adecler to confirm, the following actions are now queued:

  • check documentation-compliance

There are 2 requests in the queue ahead of you.

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

Labels

type:bug Error or unexpected behaviour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BHoM_Engine: Unsatisfiable generic constraint on any exposed method faults Caller's static initialiser

2 participants