Skip to content

Inline & strip down ExpressionShortcuts - #669

Open
TheConstructor wants to merge 2 commits into
Handlebars-Net:masterfrom
TheConstructor:feature/expression-shortcuts
Open

Inline & strip down ExpressionShortcuts#669
TheConstructor wants to merge 2 commits into
Handlebars-Net:masterfrom
TheConstructor:feature/expression-shortcuts

Conversation

@TheConstructor

Copy link
Copy Markdown
Contributor

So we now have NRT and I really like it! But currently we get some warnings during the build, mostly related to ExpressionShortcuts. I looked into it and created oformaniuk/ExpressionShortcuts#5, that would allow to get rid of the NRT-warnings.

Over a month has passed and the last change to any branch of that repository is currently 6 years old.

Now this library doesn't use everything of ExpressionShortcuts, and so I started out by adding an annotated copy of ExpressionShortcuts and then tried to strip out as many unnecessary features as possible, to not introduce a higher maintenance burden than necessary. I also tried to simplify a bunch of things - 6 years is quite some time in programming after all - and judging by the tests I may have been successful.

@rexm

rexm commented Aug 12, 2026

Copy link
Copy Markdown
Member

I have no idea what any of this means:

I looked into it and created oformaniuk/ExpressionShortcuts#5, that would allow to get rid of the NRT-warnings.

Over a month has passed and the last change to any branch of that repository is currently 6 years old.

Now this library doesn't use everything of ExpressionShortcuts, and so I started out by adding an annotated copy of ExpressionShortcuts and then tried to strip out as many unnecessary features as possible, to not introduce a higher maintenance burden than necessary. I also tried to simplify a bunch of things - 6 years is quite some time in programming after all - and judging by the tests I may have been successful.

A pull request description should describe the problem or opportunity, and explain the solution and intended impact. This is tracing the history of a change you made on an abandoned repository. Can you try again?

@oformaniuk

Copy link
Copy Markdown
Member

ExpressionShortcuts already inlines source code into the Handlebars package - it is distributed as source-code NuGet.
Can you elaborate on what issues/warnings you see and whether they can be fixed in the original package?

@TheConstructor

TheConstructor commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

Sorry for the late reply.

Which build warnings are fixed by this PR?

I just pulled up https://github.com/Handlebars-Net/Handlebars.Net/actions/runs/31321612216/job/93265376015?pr=668 which is the build of the last merged PR, and expanded the Build-step. The following NRT (Nullable-Reference-Type) Warnings appear because ExpressionShortcuts is not currently annotated (and some more):

Long list of warnings
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionShortcuts.cs(61,67): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionExtractorVisitor.cs(73,106): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.1]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionShortcuts.cs(73,73): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionUtils.cs(75,109): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.1]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionShortcuts.cs(221,60): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionUtils.cs(80,97): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.1]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionShortcuts.cs(297,68): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionShortcuts.cs(61,67): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.1]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionUtils.cs(75,109): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionShortcuts.cs(73,73): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.1]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionUtils.cs(80,97): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionShortcuts.cs(221,60): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.1]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionExtractorVisitor.cs(73,106): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionShortcuts.cs(297,68): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.1]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\TryCatchFinallyBuilder.cs(18,18): warning CS8618: Non-nullable field '_finallyBody' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionContainer.cs(95,73): warning CS8603: Possible null reference return. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.1]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\TryCatchFinallyBuilder.cs(18,18): warning CS8618: Non-nullable field '_body' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\TryCatchFinallyBuilder.cs(18,18): warning CS8618: Non-nullable field '_finallyBody' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.1]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ConditionBuilder.cs(16,18): warning CS8618: Non-nullable field '_condition' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\TryCatchFinallyBuilder.cs(18,18): warning CS8618: Non-nullable field '_body' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.1]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ConditionBuilder.cs(16,18): warning CS8618: Non-nullable field '_then' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ConditionBuilder.cs(16,18): warning CS8618: Non-nullable field '_condition' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.1]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ConditionBuilder.cs(16,18): warning CS8618: Non-nullable field '_else' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ConditionBuilder.cs(16,18): warning CS8618: Non-nullable field '_then' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.1]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionContainer.cs(95,73): warning CS8603: Possible null reference return. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ConditionBuilder.cs(16,18): warning CS8618: Non-nullable field '_else' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.1]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ConditionBuilder.cs(88,42): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\TryCatchFinallyBuilder.cs(29,49): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.1]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ConditionBuilder.cs(135,42): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ConditionBuilder.cs(88,42): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.1]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\TryCatchFinallyBuilder.cs(29,49): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ConditionBuilder.cs(135,42): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.1]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\SwitchBuilder.cs(36,18): warning CS8618: Non-nullable field 'DefaultCase' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\SwitchBuilder.cs(36,18): warning CS8618: Non-nullable field 'DefaultCase' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.1]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\SwitchBuilder.cs(36,18): warning CS8618: Non-nullable property 'ComparerMethod' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\SwitchBuilder.cs(36,18): warning CS8618: Non-nullable property 'ComparerMethod' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.1]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionExtractorVisitor.cs(76,56): warning CS8603: Possible null reference return. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionExtractorVisitor.cs(76,56): warning CS8603: Possible null reference return. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=netstandard2.1]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionShortcuts.cs(61,67): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net10.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionShortcuts.cs(73,73): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net10.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionUtils.cs(75,109): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net10.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionUtils.cs(80,97): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net10.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionShortcuts.cs(221,60): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net10.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionShortcuts.cs(297,68): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net10.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionExtractorVisitor.cs(9,36): warning CS8765: Nullability of type of parameter 'node' doesn't match overridden member (possibly because of nullability attributes). [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net10.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionExtractorVisitor.cs(73,106): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net10.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\TryCatchFinallyBuilder.cs(18,18): warning CS8618: Non-nullable field '_finallyBody' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net10.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\TryCatchFinallyBuilder.cs(18,18): warning CS8618: Non-nullable field '_body' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net10.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\TryCatchFinallyBuilder.cs(29,49): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net10.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ConditionBuilder.cs(16,18): warning CS8618: Non-nullable field '_condition' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net10.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ConditionBuilder.cs(16,18): warning CS8618: Non-nullable field '_then' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net10.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ConditionBuilder.cs(16,18): warning CS8618: Non-nullable field '_else' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net10.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ConditionBuilder.cs(88,42): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net10.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ConditionBuilder.cs(135,42): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net10.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\SwitchBuilder.cs(36,18): warning CS8618: Non-nullable field 'DefaultCase' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net10.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\SwitchBuilder.cs(36,18): warning CS8618: Non-nullable property 'ComparerMethod' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net10.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionContainer.cs(95,73): warning CS8603: Possible null reference return. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net10.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionExtractorVisitor.cs(23,40): warning CS8604: Possible null reference argument for parameter 'value' in 'Expression ExpressionExtractorVisitor.ConvertToExpression(object value, Func<Expression, Expression> visit = null)'. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net10.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionExtractorVisitor.cs(32,33): warning CS8602: Dereference of a possibly null reference. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net10.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionExtractorVisitor.cs(76,56): warning CS8603: Possible null reference return. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net10.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionShortcuts.cs(214,42): warning CS8604: Possible null reference argument for parameter 'constructor' in 'NewExpression Expression.New(ConstructorInfo constructor)'. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net10.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionUtils.cs(85,43): warning CS8604: Possible null reference argument for parameter 'constructor' in 'NewExpression Expression.New(ConstructorInfo constructor, IEnumerable<Expression>? arguments)'. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net10.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionUtils.cs(90,50): warning CS8620: Argument of type 'Expression?[]' cannot be used for parameter 'expressions' of type 'IEnumerable<Expression>' in 'IEnumerable<Expression> ExpressionUtils.ReplaceParameters(IEnumerable<Expression> expressions, IList<Expression> newValues)' due to differences in the nullability of reference types. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net10.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionUtils.cs(90,32): warning CS8600: Converting null literal or possible null value to non-nullable type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net10.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionUtils.cs(94,53): warning CS8604: Possible null reference argument for parameter 'expression' in 'UnaryExpression Expression.Convert(Expression expression, Type type)'. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net10.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionUtils.cs(94,63): warning CS8604: Possible null reference argument for parameter 'type' in 'UnaryExpression Expression.Convert(Expression expression, Type type)'. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net10.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionUtils.cs(75,109): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net8.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionUtils.cs(80,97): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net8.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionShortcuts.cs(61,67): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net8.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionShortcuts.cs(73,73): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net8.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionShortcuts.cs(221,60): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net8.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionShortcuts.cs(297,68): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net8.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionExtractorVisitor.cs(9,36): warning CS8765: Nullability of type of parameter 'node' doesn't match overridden member (possibly because of nullability attributes). [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net8.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\ExpressionExtractorVisitor.cs(73,106): warning CS8625: Cannot convert null literal to non-nullable reference type. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net8.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\TryCatchFinallyBuilder.cs(18,18): warning CS8618: Non-nullable field '_finallyBody' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net8.0]
Warning: C:\Users\runneradmin\.nuget\packages\expressionshortcuts\1.0.4.39\contentFiles\cs\netstandard2.0\ExpressionShortcuts\TryCatchFinallyBuilder.cs(18,18): warning CS8618: Non-nullable field '_body' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable. [D:\a\Handlebars.Net\Handlebars.Net\source\Handlebars\Handlebars.csproj::TargetFramework=net8.0]

When I first introduced the NRT-Annotations in the project Rider would allow me to edit the included sources from the ExpressionShortcuts-package in my local store - not very helpful. I reverted the changes to my locally cached copy of course after realizing, and created oformaniuk/ExpressionShortcuts#5 instead.

I definitely hope Rider fixes the way it handles source-files contributed by NuGet-references.

An issue solved

Not included in oformaniuk/ExpressionShortcuts#5 as I only realized the root-cause during the removal of stuff not needed from ExpressionShortcuts in Handlebars.Net.

When I set out to write #606 I came across PartialBinder - and wondered about the passage

source/Handlebars/Compiler/Translation/Expression/PartialBinder.cs lines 36 - 94
            if (decorators.Count > 0)
            {
                var bindingContext = CompilationContext.Args.BindingContext;
                var writer = CompilationContext.Args.EncodedWriter;

                var parentContext = bindingContext;
                if (pex.Argument != null || partialBlockTemplate != null)
                {
                    var value = pex.Argument != null
                        ? Arg<object?>(FunctionBuilder.Reduce(pex.Argument, CompilationContext, out _))
                        : bindingContext.Property(o => o.Value);

                    var partialTemplate = Arg(partialBlockTemplate);
                    bindingContext = bindingContext.Call(o => o.CreateChildContext(value, partialTemplate));
                }

                var partialName = Cast<string>(pex.PartialName);
                var configuration = Arg(CompilationContext.Configuration);
                var isBlock = Arg(pex.IsBlock);
                var indent = Arg(pex.Indent);
                var templateDelegate = FunctionBuilder.Compile(
                    new []
                    {
                        Call(() =>
                            InvokePartialWithFallback(partialName, bindingContext, writer, (ICompiledHandlebarsConfiguration) configuration, isBlock, indent) // NOSONAR S1944 — ExpressionShortcuts operator; not a runtime hierarchy cast
                        ).Expression
                    },
                    CompilationContext,
                    out _
                );

                var decorator = decorators.Compile(CompilationContext);
                return Call(() => decorator.Invoke(writer, parentContext, templateDelegate))
                    .Call(f => f.Invoke(writer, parentContext));
            }
            else
            {
                var bindingContext = CompilationContext.Args.BindingContext;
                var writer = CompilationContext.Args.EncodedWriter;

                if (pex.Argument != null || partialBlockTemplate != null)
                {
                    var value = pex.Argument != null
                        ? Arg<object?>(FunctionBuilder.Reduce(pex.Argument, CompilationContext, out _))
                        : bindingContext.Property(o => o.Value);

                    var partialTemplate = Arg(partialBlockTemplate);
                    bindingContext = bindingContext.Call(o => o.CreateChildContext(value, partialTemplate));
                }

                var partialName = Cast<string>(pex.PartialName);
                var configuration = Arg(CompilationContext.Configuration);
                var isBlock = Arg(pex.IsBlock);
                var indent = Arg(pex.Indent);

                return Call(() =>
                    InvokePartialWithFallback(partialName, bindingContext, writer, (ICompiledHandlebarsConfiguration) configuration, isBlock, indent)
                );
            }

If you look closely both branches up to var indent = Arg(pex.Indent); are identical except for the var parentContext = bindingContext;-line, which shouldn't change the output of the method, if it was happening vor both branches.

Still just moving the common part above and outside the branches lead to tests failing.

This is due to ExpressionShortcuts' ExpressionExtractorVisitor.VisitMember. It handles MemberExpression build over an ConstantExpression to remove the ExpressionContainer-magic. If it fails, the expression can not be evaluated correctly.

So why did it fail?

In the decorator-case the compiler decides to nest its created classes:

  [CompilerGenerated]
  private sealed class <>c__DisplayClass7_2
  {
    [Nullable(0)]
    public DecoratorDelegate decorator;
    [Nullable(0)]
    public TemplateDelegate templateDelegate;
    [Nullable(0)]
    public PartialBinder.<>c__DisplayClass7_0 CS$<>8__locals1;

    public <>c__DisplayClass7_2()
    {
      base..ctor();
    }
  }

I accounted for that in UnpackExpressionContainerVisitor.ExtractFieldOrConstantValue and I believe to have seen similar code in LinqKit.

I feel like we shouldn't have code break just by moving unchanged lines one scope up.

@oformaniuk if you like I can write a separate PR for that change for ExpressionShortcuts, too.

Why this PR?

  • I like to have as few warnings in the build output as possible. In fact, I even prefer to run PR-builds with warnings-as-errors. Not all warnings are big problems, but the more warnings there are, the easier it is to miss the important ones.
  • As stated in my initial comment I tried to solve the warnings upstream, but after 3 month and the library not having a single commit in 6 years, I was having the feeling there might be no reaction. (This may become irrelevant)
  • And lastly of course the fix to being unable to de-duplicate the code in PartialBinder. I am sure there are other parts of the project were the compiler might get the idea to generate a nested class to provide values into an expression-tree. This should improve the development-experience in all those cases. And I can of course do that as follow-up PR.

@rexm to address your comment: I thought getting rid of a lot of warnings would be self-explanatory, and wanted to show you why I make this your problem and not the upstream's (ExpressionShortcut's) problem, which causes these warnings. I tought you would ask otherwise

@oformaniuk Did I answer your question now? I had hoped, that I addressed the question in my initial comment and the PR with your repository. Don't hesitate to ask for details

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.

3 participants