Skip to content
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ namespace __GeneratedComponent
using global::System.Linq;
using global::System.Threading.Tasks;
using global::Microsoft.AspNetCore.Components;
#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: (729:17,0 [11] )
Generated Location: (775:19,0 [11] )
|IDisposable|

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

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

Source Location: (132:6,12 [37] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/BasicComponent.cshtml)
|
void IDisposable.Dispose(){ }
|
Generated Location: (1778:52,12 [37] )
Generated Location: (1824:54,12 [37] )
|
void IDisposable.Dispose(){ }
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ namespace __GeneratedComponent
using global::System.Linq;
using global::System.Threading.Tasks;
using global::Microsoft.AspNetCore.Components;
#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),
// (12,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(12, 62));
}
else
{
compiled.Diagnostics.Verify(
// (12,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(12, 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
// (25,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(23, 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(25, 91)
// (19,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(17, 138));
: Diagnostic(ErrorCode.ERR_BadArgCount, "TypeCheck<global::System.String>").WithArguments("TypeCheck", "2").WithLocation(19, 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 @@ -123,7 +123,9 @@ namespace Test
using global::System.Linq;
using global::System.Threading.Tasks;
using global::Microsoft.AspNetCore.Components;
#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 @@ -8,7 +8,9 @@ namespace Test
using global::System.Linq;
using global::System.Threading.Tasks;
using global::Microsoft.AspNetCore.Components;
#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: (1072:25,26 [1] )
Generated Location: (1118:27,26 [1] )
|c|

Source Location: (44:0,44 [1] x:\dir\subdir\Test\TestComponent.cshtml)
|c|
Generated Location: (1259:33,44 [1] )
Generated Location: (1305:35,44 [1] )
|c|

Source Location: (13:0,13 [11] x:\dir\subdir\Test\TestComponent.cshtml)
|MyParameter|
Generated Location: (1505:43,13 [11] )
Generated Location: (1551:45,13 [11] )
|MyParameter|

Source Location: (29:0,29 [13] x:\dir\subdir\Test\TestComponent.cshtml)
|BoolParameter|
Generated Location: (1742:52,29 [13] )
Generated Location: (1788:54,29 [13] )
|BoolParameter|

Source Location: (60:2,7 [42] x:\dir\subdir\Test\TestComponent.cshtml)
|
private MyClass<string> c = new();
|
Generated Location: (2165:70,7 [42] )
Generated Location: (2211:72,7 [42] )
|
private MyClass<string> c = new();
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ namespace Test
using global::System.Linq;
using global::System.Threading.Tasks;
using global::Microsoft.AspNetCore.Components;
#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: (1065:25,19 [4] )
Generated Location: (1111:27,19 [4] )
|true|

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

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

Source Location: (32:0,32 [1] x:\dir\subdir\Test\TestComponent.cshtml)
|c|
Generated Location: (1589:49,32 [1] )
Generated Location: (1635:51,32 [1] )
|c|

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

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

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

Source Location: (128:4,4 [15] x:\dir\subdir\Test\TestComponent.cshtml)
|ObjectParameter|
Generated Location: (2702:87,4 [15] )
Generated Location: (2748:89,4 [15] )
|ObjectParameter|

Source Location: (19:0,19 [11] x:\dir\subdir\Test\TestComponent.cshtml)
|MyParameter|
Generated Location: (2933:96,19 [11] )
Generated Location: (2979:98,19 [11] )
|MyParameter|

Source Location: (161:6,7 [42] x:\dir\subdir\Test\TestComponent.cshtml)
|
private MyClass<string> c = new();
|
Generated Location: (3354:114,7 [42] )
Generated Location: (3400:116,7 [42] )
|
private MyClass<string> c = new();
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ namespace Test
using global::System.Linq;
using global::System.Threading.Tasks;
using global::Microsoft.AspNetCore.Components;
#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: (947:25,26 [1] )
Generated Location: (993:27,26 [1] )
|c|

Source Location: (42:2,7 [34] x:\dir\subdir\Test\TestComponent.cshtml)
|
private MyClass c = new();
|
Generated Location: (1618:46,7 [34] )
Generated Location: (1664:48,7 [34] )
|
private MyClass c = new();
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ namespace Test
using global::System.Linq;
using global::System.Threading.Tasks;
using global::Microsoft.AspNetCore.Components;
#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: (947:25,26 [7] )
Generated Location: (993:27,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: (1636:46,7 [68] )
Generated Location: (1682:48,7 [68] )
|
private MyClass c1 = new();
private MyClass c2 = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ namespace Test
using global::System.Linq;
using global::System.Threading.Tasks;
using global::Microsoft.AspNetCore.Components;
#nullable restore
public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
#nullable disable
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
Expand Down
Loading