Skip to content

Commit

Permalink
Fix generation of ArgumentNullException in nullable context
Browse files Browse the repository at this point in the history
  • Loading branch information
k94ll13nn3 committed Mar 9, 2022
1 parent 514880e commit 0808b18
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/AutoConstructor.Generator/AutoConstructorGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ private static FieldInfo GetFieldInfo(IFieldSymbol fieldSymbol, Compilation comp
type,
type.IsReferenceType && type.NullableAnnotation == NullableAnnotation.Annotated,
summaryText,
type.NullableAnnotation != NullableAnnotation.NotAnnotated && emitNullChecks);
type.IsReferenceType && type.NullableAnnotation == NullableAnnotation.None && emitNullChecks);
}

private static T? GetParameterValue<T>(string parameterName, ImmutableArray<IParameterSymbol> parameters, ImmutableArray<TypedConstant> arguments)
Expand Down
12 changes: 9 additions & 3 deletions tests/AutoConstructor.Tests/GeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -523,17 +523,23 @@ public async Task Run_WithNullableReferenceType_ShouldGenerateClass()
[AutoConstructor]
internal partial class Test
{
private readonly string? _t;
private readonly string? _t1;
private readonly string _t2;
private readonly int _d1;
private readonly int? _d2;
}
}";
const string generated = @"#nullable enable
namespace Test
{
partial class Test
{
public Test(string? t)
public Test(string? t1, string t2, int d1, int? d2)
{
this._t = t ?? throw new System.ArgumentNullException(nameof(t));
this._t1 = t1;
this._t2 = t2;
this._d1 = d1;
this._d2 = d2;
}
}
}
Expand Down

0 comments on commit 0808b18

Please sign in to comment.