Skip to content
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ namespace __GeneratedComponent
using global::Microsoft.AspNetCore.Components;
#line default
#line hidden
#nullable restore
public partial class AspNetCore_3708c9fcd2e1ecb6cbaba92bcc60927f830690f42092c4aa1a7275c2f37020fd : global::Microsoft.AspNetCore.Components.ComponentBase, IDisposable
#nullable disable
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
Source Location: (12:0,12 [11] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/BasicComponent.cshtml)
|IDisposable|
Generated Location: (767:19,0 [11] )
Generated Location: (813:21,0 [11] )
|IDisposable|

Source Location: (38:1,13 [15] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/BasicComponent.cshtml)
|this.ToString()|
Generated Location: (1367:37,13 [15] )
Generated Location: (1413:39,13 [15] )
|this.ToString()|

Source Location: (79:3,5 [29] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/BasicComponent.cshtml)
|string.Format("{0}", "Hello")|
Generated Location: (1564:45,6 [29] )
Generated Location: (1610:47,6 [29] )
|string.Format("{0}", "Hello")|

Source Location: (132:6,12 [37] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/BasicComponent.cshtml)
|
void IDisposable.Dispose(){ }
|
Generated Location: (1816:54,12 [37] )
Generated Location: (1862:56,12 [37] )
|
void IDisposable.Dispose(){ }
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ namespace __GeneratedComponent
using global::Microsoft.AspNetCore.Components;
#line default
#line hidden
#nullable restore
public partial class AspNetCore_3708c9fcd2e1ecb6cbaba92bcc60927f830690f42092c4aa1a7275c2f37020fd : global::Microsoft.AspNetCore.Components.ComponentBase, IDisposable
#nullable disable
{
#pragma warning disable 1998
protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4877,6 +4877,95 @@ @preservewhitespace someVariable
Assert.Collection(generated.Diagnostics, d => { Assert.Equal("RZ1038", d.Id); });
}

[IntegrationTestFact, WorkItem("https://github.com/dotnet/razor/issues/7169")]
public void InheritsDirective_NullableReferenceType()
{
// Arrange
AdditionalSyntaxTrees.Add(Parse("""
namespace Test;

public class BaseComponent<T> : Microsoft.AspNetCore.Components.ComponentBase
{
protected T _field = default!;
}
"""));

// Act
var generated = CompileToCSharp("""
@inherits BaseComponent<string?>

<h1>My component</h1>
@(_field.ToString())
""",
nullableEnable: true);

// Assert
AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
var compiled = CompileToAssembly(generated, throwOnFailure: false);
if (DesignTime)
{
compiled.Diagnostics.Verify(
// x:\dir\subdir\Test\TestComponent.cshtml(4,7): warning CS8602: Dereference of a possibly null reference.
// __o = _field.ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "_field").WithLocation(4, 7));
}
else
{
compiled.Diagnostics.Verify(
// x:\dir\subdir\Test\TestComponent.cshtml(4,3): warning CS8602: Dereference of a possibly null reference.
// __builder.AddContent(1, _field.ToString());
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "_field").WithLocation(4, 3));
}
}

[IntegrationTestFact, WorkItem("https://github.com/dotnet/razor/issues/7169")]
public void InheritsDirective_NullableReferenceType_NullableDisabled()
{
// Arrange
AdditionalSyntaxTrees.Add(Parse("""
namespace Test;

public class BaseComponent<T> : Microsoft.AspNetCore.Components.ComponentBase
{
protected T _field;
}
"""));

// Act
var generated = CompileToCSharp("""
@inherits BaseComponent<string?>

<h1>My component</h1>
@(_field.ToString())
""",
nullableEnable: false,
throwOnFailure: false);

// Assert
Assert.Empty(generated.Diagnostics);
AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
var compiled = CompileToAssembly(generated, throwOnFailure: false);
if (DesignTime)
{
compiled.Diagnostics.Verify(
// x:\dir\subdir\Test\TestComponent.cshtml(1,21): warning CS8669: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. Auto-generated code requires an explicit '#nullable' directive in source.
// BaseComponent<string?> __typeHelper = default!;
Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotationInGeneratedCode, "?").WithLocation(1, 21),
// (14,62): warning CS8669: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. Auto-generated code requires an explicit '#nullable' directive in source.
// public partial class TestComponent : BaseComponent<string?>
Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotationInGeneratedCode, "?").WithLocation(14, 62));
}
else
{
compiled.Diagnostics.Verify(
// (14,62): warning CS8669: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. Auto-generated code requires an explicit '#nullable' directive in source.
// public partial class TestComponent : BaseComponent<string?>
Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotationInGeneratedCode, "?").WithLocation(14, 62));
}
}

#endregion

#region EventCallback
Expand Down Expand Up @@ -10219,12 +10308,12 @@ public class MyComponent : ComponentBase
// x
Diagnostic(ErrorCode.ERR_SyntaxError, "").WithArguments(",").WithLocation(1, 32),
DesignTime
// (23,91): error CS1501: No overload for method 'TypeCheck' takes 2 arguments
// (27,91): error CS1501: No overload for method 'TypeCheck' takes 2 arguments
// __o = global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<global::System.String>(
? Diagnostic(ErrorCode.ERR_BadArgCount, "TypeCheck<global::System.String>").WithArguments("TypeCheck", "2").WithLocation(25, 91)
// (17,138): error CS1501: No overload for method 'TypeCheck' takes 2 arguments
? Diagnostic(ErrorCode.ERR_BadArgCount, "TypeCheck<global::System.String>").WithArguments("TypeCheck", "2").WithLocation(27, 91)
// (21,138): error CS1501: No overload for method 'TypeCheck' takes 2 arguments
// __builder.AddComponentParameter(1, "StringProperty", global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<global::System.String>(
: Diagnostic(ErrorCode.ERR_BadArgCount, "TypeCheck<global::System.String>").WithArguments("TypeCheck", "2").WithLocation(19, 138));
: Diagnostic(ErrorCode.ERR_BadArgCount, "TypeCheck<global::System.String>").WithArguments("TypeCheck", "2").WithLocation(21, 138));
Assert.NotEmpty(generated.Diagnostics);
}

Expand Down Expand Up @@ -10898,12 +10987,12 @@ @using Microsoft.AspNetCore.Components.Web
AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
var result = CompileToAssembly(generated, throwOnFailure: false);
result.Diagnostics.Verify(DesignTime
// (39,85): error CS7036: There is no argument given that corresponds to the required parameter 'value' of 'RuntimeHelpers.TypeCheck<T>(T)'
// (41,85): error CS7036: There is no argument given that corresponds to the required parameter 'value' of 'RuntimeHelpers.TypeCheck<T>(T)'
// global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<string>();
? Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "TypeCheck<string>").WithArguments("value", "Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<T>(T)").WithLocation(39, 85)
// (34,105): error CS7036: There is no argument given that corresponds to the required parameter 'value' of 'RuntimeHelpers.TypeCheck<T>(T)'
? Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "TypeCheck<string>").WithArguments("value", "Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<T>(T)").WithLocation(41, 85)
// (36,105): error CS7036: There is no argument given that corresponds to the required parameter 'value' of 'RuntimeHelpers.TypeCheck<T>(T)'
// string __formName = global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<string>();
: Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "TypeCheck<string>").WithArguments("value", "Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<T>(T)").WithLocation(34, 105));
: Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "TypeCheck<string>").WithArguments("value", "Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<T>(T)").WithLocation(36, 105));
}

[IntegrationTestFact, WorkItem("https://github.com/dotnet/razor/issues/9077")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ namespace Test
using global::Microsoft.AspNetCore.Components;
#line default
#line hidden
#nullable restore
public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
#nullable disable
{
#pragma warning disable 1998
protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ namespace Test
using global::Microsoft.AspNetCore.Components;
#line default
#line hidden
#nullable restore
public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
#nullable disable
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
Source Location: (26:0,26 [1] x:\dir\subdir\Test\TestComponent.cshtml)
|c|
Generated Location: (1110:27,26 [1] )
Generated Location: (1156:29,26 [1] )
|c|

Source Location: (44:0,44 [1] x:\dir\subdir\Test\TestComponent.cshtml)
|c|
Generated Location: (1297:35,44 [1] )
Generated Location: (1343:37,44 [1] )
|c|

Source Location: (13:0,13 [11] x:\dir\subdir\Test\TestComponent.cshtml)
|MyParameter|
Generated Location: (1543:45,13 [11] )
Generated Location: (1589:47,13 [11] )
|MyParameter|

Source Location: (29:0,29 [13] x:\dir\subdir\Test\TestComponent.cshtml)
|BoolParameter|
Generated Location: (1780:54,29 [13] )
Generated Location: (1826:56,29 [13] )
|BoolParameter|

Source Location: (60:2,7 [42] x:\dir\subdir\Test\TestComponent.cshtml)
|
private MyClass<string> c = new();
|
Generated Location: (2203:72,7 [42] )
Generated Location: (2249:74,7 [42] )
|
private MyClass<string> c = new();
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ namespace Test
using global::Microsoft.AspNetCore.Components;
#line default
#line hidden
#nullable restore
public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
#nullable disable
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
Source Location: (55:1,19 [4] x:\dir\subdir\Test\TestComponent.cshtml)
|true|
Generated Location: (1103:27,19 [4] )
Generated Location: (1149:29,19 [4] )
|true|

Source Location: (112:3,23 [9] x:\dir\subdir\Test\TestComponent.cshtml)
|() => { }|
Generated Location: (1280:35,23 [9] )
Generated Location: (1326:37,23 [9] )
|() => { }|

Source Location: (145:4,21 [1] x:\dir\subdir\Test\TestComponent.cshtml)
|c|
Generated Location: (1452:43,21 [1] )
Generated Location: (1498:45,21 [1] )
|c|

Source Location: (32:0,32 [1] x:\dir\subdir\Test\TestComponent.cshtml)
|c|
Generated Location: (1627:51,32 [1] )
Generated Location: (1673:53,32 [1] )
|c|

Source Location: (40:1,4 [13] x:\dir\subdir\Test\TestComponent.cshtml)
|BoolParameter|
Generated Location: (2092:62,4 [13] )
Generated Location: (2138:64,4 [13] )
|BoolParameter|

Source Location: (66:2,4 [15] x:\dir\subdir\Test\TestComponent.cshtml)
|StringParameter|
Generated Location: (2306:71,4 [15] )
Generated Location: (2352:73,4 [15] )
|StringParameter|

Source Location: (93:3,4 [17] x:\dir\subdir\Test\TestComponent.cshtml)
|DelegateParameter|
Generated Location: (2522:80,4 [17] )
Generated Location: (2568:82,4 [17] )
|DelegateParameter|

Source Location: (128:4,4 [15] x:\dir\subdir\Test\TestComponent.cshtml)
|ObjectParameter|
Generated Location: (2740:89,4 [15] )
Generated Location: (2786:91,4 [15] )
|ObjectParameter|

Source Location: (19:0,19 [11] x:\dir\subdir\Test\TestComponent.cshtml)
|MyParameter|
Generated Location: (2971:98,19 [11] )
Generated Location: (3017:100,19 [11] )
|MyParameter|

Source Location: (161:6,7 [42] x:\dir\subdir\Test\TestComponent.cshtml)
|
private MyClass<string> c = new();
|
Generated Location: (3392:116,7 [42] )
Generated Location: (3438:118,7 [42] )
|
private MyClass<string> c = new();
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ namespace Test
using global::Microsoft.AspNetCore.Components;
#line default
#line hidden
#nullable restore
public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
#nullable disable
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Source Location: (26:0,26 [1] x:\dir\subdir\Test\TestComponent.cshtml)
|c|
Generated Location: (985:27,26 [1] )
Generated Location: (1031:29,26 [1] )
|c|

Source Location: (42:2,7 [34] x:\dir\subdir\Test\TestComponent.cshtml)
|
private MyClass c = new();
|
Generated Location: (1656:48,7 [34] )
Generated Location: (1702:50,7 [34] )
|
private MyClass c = new();
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ namespace Test
using global::Microsoft.AspNetCore.Components;
#line default
#line hidden
#nullable restore
public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
#nullable disable
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Source Location: (26:0,26 [7] x:\dir\subdir\Test\TestComponent.cshtml)
|c1 = c2|
Generated Location: (985:27,26 [7] )
Generated Location: (1031:29,26 [7] )
|c1 = c2|

Source Location: (48:2,7 [68] x:\dir\subdir\Test\TestComponent.cshtml)
|
private MyClass c1 = new();
private MyClass c2 = new();
|
Generated Location: (1674:48,7 [68] )
Generated Location: (1720:50,7 [68] )
|
private MyClass c1 = new();
private MyClass c2 = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ namespace Test
using global::Microsoft.AspNetCore.Components;
#line default
#line hidden
#nullable restore
public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
#nullable disable
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
Expand Down
Loading