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

Improved nullable support #30

Conversation

jkurdek
Copy link
Collaborator

@jkurdek jkurdek commented May 8, 2024

No description provided.

@jkurdek jkurdek changed the title added unit tests for nullable disabled Improved nullable support May 8, 2024
@jkurdek jkurdek requested a review from simonrozsival May 8, 2024 13:53
Copy link
Owner

@simonrozsival simonrozsival left a comment

Choose a reason for hiding this comment

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

I like the end-to-end tests that you added. I'm not sure if we should transfor the path as it's parsed or if we should just modify the code that produces the C# code. I'm leaning towards the latter, it seems less magic. The code writer should just have some a parameter like bool considerAllReferenceTypesPotentiallyNullable and generate a nullability check in the setter for each reference type and always add ?s after accessing a reference type when constructing the partial getters for the handlers array.

Comment on lines 70 to 74
else if (previousPart is MemberAccess memberAccess && !memberAccess.IsMemberValueType && _considerAllReferenceTypesPotentiallyNullable)
{
AddIsExpression("{}");
_expression = AccessExpressionBuilder.Build(_expression, memberAccess);
}
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think this is equivalent to the removed condition in Setter.From. If this didn't break any existing test though, I need to think a bit if we are missing a test scenario or not.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is still WIP. The previous version contained a bug. When we had nullable source and first access in the path was conditionalAccess it generated if p0 is {} p1.

Copy link
Owner

Choose a reason for hiding this comment

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

oh, good catch!

@jkurdek
Copy link
Collaborator Author

jkurdek commented May 10, 2024

TODO:

  • Indexer support
  • Review tests
  • Add additional tests to SetterBuilderTests
  • Refactor

@jkurdek jkurdek marked this pull request as ready for review May 13, 2024 08:56
Comment on lines 50 to 56
public void AddPart(IPathPart nextPart)
{
_previousPart = HandlePreviousPart(nextPart);
var newPart = HandleCurrentPart(nextPart);
_previousPart = _currentPart;
_currentPart = newPart;

}
Copy link
Owner

Choose a reason for hiding this comment

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

Thinking out loud: this needs refactoring, the nextPart, newPart, _currentPart, _previousPart naming is confusing.

Comment on lines 174 to 175
var isReferenceType = typeSymbol?.IsReferenceType ?? false;
var isNullableValueType = typeSymbol != null ? BindingGenerationUtilities.IsNullableValueType(typeSymbol) : false;
Copy link
Owner

Choose a reason for hiding this comment

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

There's quite a lot of code duplication going on here and it's getting hard to read. We should consider moving this to a separate method at least.

foreach (var part in path)
{
var previousExpression = nextExpression;
nextExpression = AccessExpressionBuilder.Build(previousExpression, MaybeWrapInConditionalAccess(part, forceConditonalAccessToNextPart));
forceConditonalAccessToNextPart = part is Cast;
var isNullableReferenceType = part is MemberAccess memberAccess && !memberAccess.IsValueType;
Copy link
Owner

Choose a reason for hiding this comment

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

We need a check for IndexAccess here as well + a unit test that covers that case.

jkurdek and others added 3 commits May 14, 2024 15:41
Co-authored-by: Šimon Rozsíval <simon@rozsival.com>
Co-authored-by: Šimon Rozsíval <simon@rozsival.com>
Co-authored-by: Šimon Rozsíval <simon@rozsival.com>
@simonrozsival simonrozsival merged commit bff3429 into simonrozsival:binding-source-generator May 14, 2024
2 checks passed
simonrozsival added a commit that referenced this pull request Jun 4, 2024
* added unit tests for nullable disabled

* added integration tests for nullable disabled

* add nullable disabled support for reference types

* wip: added support for nullable disabled on value types

* improved integration tests

* initialize support for indexers

* add indexers support to SetterBuilder

* added additional tests for setter builder

* cleaned up SetterBuilder

* Fixed nullable access with BindingTransformer

Co-authored-by: Šimon Rozsíval <simon@rozsival.com>

* Removed IsNullableValueType property

Co-authored-by: Šimon Rozsíval <simon@rozsival.com>

* Cleaned up nullability

Co-authored-by: Šimon Rozsíval <simon@rozsival.com>

---------

Co-authored-by: Šimon Rozsíval <simon@rozsival.com>
simonrozsival added a commit that referenced this pull request Jun 5, 2024
* Add new public API SetBinding<TSource, TProperty>

* Add source generator skeleton

WIP

* Setup unit tests for binding intermediate representation

* Added basic nullability support

* Remove unnecessary Id from the binding record

* Generate casts

* Split index and member access

* Cleanup

* Update test case

* Cleanup

* Fix the semantic of conditional access

* add as-cast suport to source generator

* improve nullability check

* specify params in tests only when not default

* simplify diagnostics

* move path parser to separate class

* small cleanup

* Get nullability right in binding representation tests

Co-authored-by: Šimon Rozsíval <simon@rozsival.com>

* Fix path parse to work with improved tests

* Integration tests (#14)

* create assert extensions

Co-authored-by: Šimon Rozsíval <simon@rozsival.com>

* added basic binding integration test

* fixed unit tests

Co-authored-by: Šimon Rozsíval <simon@rozsival.com>

* added cast integration test

Co-authored-by: Šimon Rozsíval <simon@rozsival.com>

* cleaned up tests

* remove nullableEnabled param from PathParser

* more clean up

* Enable diagnostic generation in PathParser

* refactored parse path function

* further parsePath refactoring

* refactored source generator utilities

* fixed lambda return type nullability inference

* replaced linkedList with list in ParsePath

---------

Co-authored-by: Šimon Rozsíval <simon@rozsival.com>

* Implement setters (#16)

* Make Cast record non-nested

* Simplify AccessExpressionBuilder

* Add SetterBuilder

* Fix BindingCodeWriter

* Fix tests

* Make SetterBuilder private inside Setter

* Remove unnecessary IsConditional

* Simplify indexes (#18)

* Fix overload check (#20)

* fixed correct overload check

* disable test

* Implement detection of writable properties (#19)

* Add TODOs to change arrays to equatable arrays

* Add projects to solutions

* Try to run unit tests in CI

* Added custom indexer support

* Fix typo

* Avoid allocating line separators array

* Hide the new SetBinding overload from editor suggestions for now

* Incremental generation tests

* replaced array with equatable array

* Added source information + formatting

* added third party licenses

* Add benchmark for source-generated SetBinding (#25)

* Add benchmark for source-generated SetBinding

* Auto-format source code

* improve overload diagnostics tests

* added more complex overload tests

* improve predicate method filtering

* improved diagnostics on overload detection

* Auto-format source code

* add ArgumentOutOfRangeException

* Auto-format source code

---------

Co-authored-by: GitHub Actions Autoformatter <autoformat@example.com>
Co-authored-by: Jeremi Kurdek <jkurdek@gmail.com>

* Improve diagnostic messages

* Improved incrementality testing (#28)

* improved incrementality testing

* added source changed test

* added different file modified test

* Add C-Style casts support (#26)

* initialized cstyle casts

* added integration and accessExpressionBuilder tests

* added explicit cast to as cast adapter

* Simplify inserting conditional access

* Add integration tests

---------

Co-authored-by: Simon Rozsival <simon@rozsival.com>

* Cleanup (#29)

* Improved nullable support (#30)

* added unit tests for nullable disabled

* added integration tests for nullable disabled

* add nullable disabled support for reference types

* wip: added support for nullable disabled on value types

* improved integration tests

* initialize support for indexers

* add indexers support to SetterBuilder

* added additional tests for setter builder

* cleaned up SetterBuilder

* Fixed nullable access with BindingTransformer

Co-authored-by: Šimon Rozsíval <simon@rozsival.com>

* Removed IsNullableValueType property

Co-authored-by: Šimon Rozsíval <simon@rozsival.com>

* Cleaned up nullability

Co-authored-by: Šimon Rozsíval <simon@rozsival.com>

---------

Co-authored-by: Šimon Rozsíval <simon@rozsival.com>

* Simplify building setter

* cleaned up methods in BindingSourceGeneratorUtilities

* replaced tuples with Result<T>

* simplified naming

* Fix and improve unit test project

* Fix bad conflict resolution in solution file

---------

Co-authored-by: Jeremi Kurdek <jkurdek@gmail.com>
Co-authored-by: Jeremi Kurdek <59935235+jkurdek@users.noreply.github.com>
Co-authored-by: GitHub Actions Autoformatter <autoformat@example.com>
@github-actions github-actions bot locked and limited conversation to collaborators Jun 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants