Improved nullable support#30
Conversation
simonrozsival
left a comment
There was a problem hiding this comment.
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.
| else if (previousPart is MemberAccess memberAccess && !memberAccess.IsMemberValueType && _considerAllReferenceTypesPotentiallyNullable) | ||
| { | ||
| AddIsExpression("{}"); | ||
| _expression = AccessExpressionBuilder.Build(_expression, memberAccess); | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
TODO:
|
| public void AddPart(IPathPart nextPart) | ||
| { | ||
| _previousPart = HandlePreviousPart(nextPart); | ||
| var newPart = HandleCurrentPart(nextPart); | ||
| _previousPart = _currentPart; | ||
| _currentPart = newPart; | ||
|
|
||
| } |
There was a problem hiding this comment.
Thinking out loud: this needs refactoring, the nextPart, newPart, _currentPart, _previousPart naming is confusing.
| var isReferenceType = typeSymbol?.IsReferenceType ?? false; | ||
| var isNullableValueType = typeSymbol != null ? BindingGenerationUtilities.IsNullableValueType(typeSymbol) : false; |
There was a problem hiding this comment.
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.
| var previousExpression = nextExpression; | ||
| nextExpression = AccessExpressionBuilder.Build(previousExpression, MaybeWrapInConditionalAccess(part, forceConditonalAccessToNextPart)); | ||
| forceConditonalAccessToNextPart = part is Cast; | ||
| var isNullableReferenceType = part is MemberAccess memberAccess && !memberAccess.IsValueType; |
There was a problem hiding this comment.
We need a check for IndexAccess here as well + a unit test that covers that case.
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>
* 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>
* 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>
No description provided.