Skip to content

Feature/add instant handle attributes#76

Merged
park-jasper merged 6 commits intomainfrom
feature/add-instant-handle-attributes
Nov 10, 2025
Merged

Feature/add instant handle attributes#76
park-jasper merged 6 commits intomainfrom
feature/add-instant-handle-attributes

Conversation

@park-jasper
Copy link
Member

The following piece of code result in Resharper generating a warning because of a capture that is modified in the outer scope:

[UnionType]
public abstract record Base
{
  public sealed record Number_(int Value) : Base;
  public sealed record Text_(string Value) : Base;
}

...

public void Test()
{
  int value = 5;
  Base b = Base.Number(6);
  value = base.Match(number: number => number.Value, text: _ => value);
}

value is captured in the text parameter, but also edited outside the capture, which can lead to unexpected effects.
In this case we know that .Match does not store the parameter for later, but rather executes it before control is returned to the calling method.
To indicate that to Resharper, the [InstantHandle] attribute can be added before the parameter, which will make the warning not appear.

To not introduce any additional dependency, this is for now only added to the code generated by FunicularSwitch.Generators which will insert it if the JetBrains.Annotations package is already referenced.

@park-jasper park-jasper requested a review from ax0l0tl November 7, 2025 09:41
@park-jasper park-jasper merged commit e8b0914 into main Nov 10, 2025
2 checks passed
@park-jasper park-jasper deleted the feature/add-instant-handle-attributes branch November 10, 2025 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants