Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure type arguments are global:: qualified #10834

Merged
merged 8 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2336,9 +2336,9 @@ public class MyComponent : ComponentBase
: [// x:\dir\subdir\Test\TestComponent.cshtml(1,27): error CS1503: Argument 1: cannot convert from 'string' to 'int'
// ParentValue
Diagnostic(ErrorCode.ERR_BadArgType, "ParentValue").WithArguments("1", "string", "int").WithLocation(1, 27),
// (38,158): error CS0029: Cannot implicitly convert type 'int' to 'string'
// __builder.AddComponentParameter(2, "ValueChanged", (global::System.Action<System.Int32>)(__value => ParentValue = __value));
Diagnostic(ErrorCode.ERR_NoImplicitConv, "__value").WithArguments("int", "string").WithLocation(38, 158)]);
// (38,166): error CS0029: Cannot implicitly convert type 'int' to 'string'
// __builder.AddComponentParameter(2, nameof(global::Test.MyComponent.ValueChanged), (global::System.Action<global::System.Int32>)(__value => ParentValue = __value));
Diagnostic(ErrorCode.ERR_NoImplicitConv, "__value").WithArguments("int", "string").WithLocation(38, 166)]);
}

[IntegrationTestFact]
Expand Down Expand Up @@ -2616,18 +2616,18 @@ public class MyComponent : ComponentBase


CompileToAssembly(generated, DesignTime
? [// (31,179): error CS0029: Cannot implicitly convert type 'int' to 'string'
// __builder.AddComponentParameter(3, "ValueExpression", global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<global::System.Linq.Expressions.Expression<System.Func<System.String>>>(() => ParentValue));
Diagnostic(ErrorCode.ERR_NoImplicitConv, "ParentValue").WithArguments("int", "string").WithLocation(38, 179),
// (31,179): error CS1662: Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type
// __builder.AddComponentParameter(3, "ValueExpression", global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<global::System.Linq.Expressions.Expression<System.Func<System.String>>>(() => ParentValue));
Diagnostic(ErrorCode.ERR_CantConvAnonMethReturns, "ParentValue").WithArguments("lambda expression").WithLocation(38, 179)]
: [// (39,258): error CS0029: Cannot implicitly convert type 'int' to 'string'
// __builder.AddComponentParameter(3, "ValueExpression", global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<global::System.Linq.Expressions.Expression<System.Func<System.String>>>(() => ParentValue));
Diagnostic(ErrorCode.ERR_NoImplicitConv, "ParentValue").WithArguments("int", "string").WithLocation(39, 258),
// (39,258): error CS1662: Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type
// __builder.AddComponentParameter(3, "ValueExpression", global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<global::System.Linq.Expressions.Expression<System.Func<System.String>>>(() => ParentValue));
Diagnostic(ErrorCode.ERR_CantConvAnonMethReturns, "ParentValue").WithArguments("lambda expression").WithLocation(39, 258)
? [// (38,195): error CS0029: Cannot implicitly convert type 'int' to 'string'
// __o = global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<global::System.Linq.Expressions.Expression<global::System.Func<global::System.String>>>(() => ParentValue);
Diagnostic(ErrorCode.ERR_NoImplicitConv, "ParentValue").WithArguments("int", "string").WithLocation(38, 195),
// (38,195): error CS1662: Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type
// __o = global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<global::System.Linq.Expressions.Expression<global::System.Func<global::System.String>>>(() => ParentValue);
Diagnostic(ErrorCode.ERR_CantConvAnonMethReturns, "ParentValue").WithArguments("lambda expression").WithLocation(38, 195)]
: [// (39,274): error CS0029: Cannot implicitly convert type 'int' to 'string'
// __builder.AddComponentParameter(3, nameof(global::Test.MyComponent.ValueExpression), global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<global::System.Linq.Expressions.Expression<global::System.Func<global::System.String>>>(() => ParentValue));
Diagnostic(ErrorCode.ERR_NoImplicitConv, "ParentValue").WithArguments("int", "string").WithLocation(39, 274),
// (39,274): error CS1662: Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type
// __builder.AddComponentParameter(3, nameof(global::Test.MyComponent.ValueExpression), global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<global::System.Linq.Expressions.Expression<global::System.Func<global::System.String>>>(() => ParentValue));
Diagnostic(ErrorCode.ERR_CantConvAnonMethReturns, "ParentValue").WithArguments("lambda expression").WithLocation(39, 274)
]);
}

Expand Down Expand Up @@ -8743,6 +8743,31 @@ public class MyComponent<TService, TKey> : ComponentBase
CompileToAssembly(generated);
}

[IntegrationTestFact, WorkItem("https://github.com/dotnet/razor/issues/10827")]
public void GenericTypeCheck()
{
var generated = CompileToCSharp("""
<TestComponent Data="null" />

@code {
private class System
{
private class String
{
}
}

[Parameter]
public List<global::System.String> Data { get; set; }
}
""");

// Assert
AssertDocumentNodeMatchesBaseline(generated.CodeDocument);
AssertCSharpDocumentMatchesBaseline(generated.CodeDocument);
CompileToAssembly(generated);
}

#endregion

#region Key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.
);
__o = global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<global::Microsoft.AspNetCore.Components.EventCallback<global::System.Int32>>(global::Microsoft.AspNetCore.Components.EventCallback.Factory.Create<global::System.Int32>(this,
global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.CreateInferredEventCallback(this, __value => ParentValue = __value, ParentValue)));
__o = global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<global::System.Linq.Expressions.Expression<System.Func<System.Int32>>>(() => ParentValue);
__o = global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<global::System.Linq.Expressions.Expression<global::System.Func<global::System.Int32>>>(() => ParentValue);
__builder.AddAttribute(-1, "ChildContent", (global::Microsoft.AspNetCore.Components.RenderFragment)((__builder2) => {
}
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ Generated Location: (1135:29,26 [11] )

Source Location: (19:0,19 [5] x:\dir\subdir\Test\TestComponent.cshtml)
|Value|
Generated Location: (2197:45,19 [5] )
Generated Location: (2213:45,19 [5] )
|Value|

Source Location: (50:1,7 [50] x:\dir\subdir\Test\TestComponent.cshtml)
|
public int ParentValue { get; set; } = 42;
|
Generated Location: (2610:63,7 [50] )
Generated Location: (2626:63,7 [50] )
|
public int ParentValue { get; set; } = 42;
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.
#line hidden
#nullable disable
);
__o = new global::System.Action<System.Int32>(
__o = new global::System.Action<global::System.Int32>(
__value => ParentValue = __value);
__builder.AddAttribute(-1, "ChildContent", (global::Microsoft.AspNetCore.Components.RenderFragment)((__builder2) => {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ Generated Location: (1135:29,26 [11] )

Source Location: (19:0,19 [5] x:\dir\subdir\Test\TestComponent.cshtml)
|Value|
Generated Location: (1668:44,19 [5] )
Generated Location: (1676:44,19 [5] )
|Value|

Source Location: (45:0,45 [5] x:\dir\subdir\Test\TestComponent.cshtml)
|Value|
Generated Location: (1915:53,45 [5] )
Generated Location: (1923:53,45 [5] )
|Value|

Source Location: (80:1,7 [50] x:\dir\subdir\Test\TestComponent.cshtml)
|
public int ParentValue { get; set; } = 42;
|
Generated Location: (2328:71,7 [50] )
Generated Location: (2336:71,7 [50] )
|
public int ParentValue { get; set; } = 42;
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.
#line hidden
#nullable disable
);
__o = new global::System.Action<System.Int32>(
__o = new global::System.Action<global::System.Int32>(
__value => ParentValue = __value);
__o = global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<global::System.Linq.Expressions.Expression<System.Func<System.Int32>>>(() => ParentValue);
__o = global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<global::System.Linq.Expressions.Expression<global::System.Func<global::System.Int32>>>(() => ParentValue);
__builder.AddAttribute(-1, "ChildContent", (global::Microsoft.AspNetCore.Components.RenderFragment)((__builder2) => {
}
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ Generated Location: (1135:29,26 [11] )

Source Location: (19:0,19 [5] x:\dir\subdir\Test\TestComponent.cshtml)
|Value|
Generated Location: (1860:45,19 [5] )
Generated Location: (1884:45,19 [5] )
|Value|

Source Location: (50:1,7 [50] x:\dir\subdir\Test\TestComponent.cshtml)
|
public int ParentValue { get; set; } = 42;
|
Generated Location: (2273:63,7 [50] )
Generated Location: (2297:63,7 [50] )
|
public int ParentValue { get; set; } = 42;
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.
#line hidden
#nullable disable
);
__o = new global::System.Action<System.Int32>(
__o = new global::System.Action<global::System.Int32>(
__value => ParentValue = __value);
__builder.AddAttribute(-1, "ChildContent", (global::Microsoft.AspNetCore.Components.RenderFragment)((__builder2) => {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ Generated Location: (1135:29,26 [11] )

Source Location: (19:0,19 [5] x:\dir\subdir\Test\TestComponent.cshtml)
|Value|
Generated Location: (1668:44,19 [5] )
Generated Location: (1676:44,19 [5] )
|Value|

Source Location: (50:1,7 [50] x:\dir\subdir\Test\TestComponent.cshtml)
|
public int ParentValue { get; set; } = 42;
|
Generated Location: (2081:62,7 [50] )
Generated Location: (2089:62,7 [50] )
|
public int ParentValue { get; set; } = 42;
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.
#line hidden
#nullable disable
);
__o = new global::System.Action<System.Int32>(
__o = new global::System.Action<global::System.Int32>(
__value => ParentValue = __value);
__builder.AddAttribute(-1, "ChildContent", (global::Microsoft.AspNetCore.Components.RenderFragment)((__builder2) => {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ Generated Location: (1131:29,22 [11] )

Source Location: (15:0,15 [5] x:\dir\subdir\Test\TestComponent.cshtml)
|Value|
Generated Location: (1656:44,15 [5] )
Generated Location: (1664:44,15 [5] )
|Value|

Source Location: (46:1,7 [50] x:\dir\subdir\Test\TestComponent.cshtml)
|
public int ParentValue { get; set; } = 42;
|
Generated Location: (2065:62,7 [50] )
Generated Location: (2073:62,7 [50] )
|
public int ParentValue { get; set; } = 42;
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.
#line hidden
#nullable disable
);
__o = new global::System.Action<System.Int32>(
__o = new global::System.Action<global::System.Int32>(
__value => ParentValue = __value);
__builder.AddAttribute(-1, "ChildContent", (global::Microsoft.AspNetCore.Components.RenderFragment)((__builder2) => {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ Generated Location: (1127:29,18 [11] )

Source Location: (11:0,11 [5] x:\dir\subdir\Test\TestComponent.cshtml)
|Value|
Generated Location: (1645:44,11 [5] )
Generated Location: (1653:44,11 [5] )
|Value|

Source Location: (42:1,7 [50] x:\dir\subdir\Test\TestComponent.cshtml)
|
public int ParentValue { get; set; } = 42;
|
Generated Location: (2051:62,7 [50] )
Generated Location: (2059:62,7 [50] )
|
public int ParentValue { get; set; } = 42;
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.
#line hidden
#nullable disable
);
__o = new global::System.Action<System.Int32>(
__o = new global::System.Action<global::System.Int32>(
__value => ParentValue = __value);
__builder.AddAttribute(-1, "ChildContent", (global::Microsoft.AspNetCore.Components.RenderFragment)((__builder2) => {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ Generated Location: (1135:29,26 [11] )

Source Location: (19:0,19 [5] x:\dir\subdir\Test\TestComponent.cshtml)
|Value|
Generated Location: (1663:44,19 [5] )
Generated Location: (1671:44,19 [5] )
|Value|

Source Location: (50:1,7 [50] x:\dir\subdir\Test\TestComponent.cshtml)
|
public int ParentValue { get; set; } = 42;
|
Generated Location: (2071:62,7 [50] )
Generated Location: (2079:62,7 [50] )
|
public int ParentValue { get; set; } = 42;
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.
#line hidden
#nullable disable
);
__o = new global::System.Action<System.Int32>(
__o = new global::System.Action<global::System.Int32>(
__value => ParentValue = __value);
__builder.AddAttribute(-1, "ChildContent", (global::Microsoft.AspNetCore.Components.RenderFragment)((__builder2) => {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Generated Location: (1135:29,26 [11] )

Source Location: (19:0,19 [5] x:\dir\subdir\Test\TestComponent.cshtml)
|Value|
Generated Location: (1668:44,19 [5] )
Generated Location: (1676:44,19 [5] )
|Value|

Source Location: (50:1,7 [105] x:\dir\subdir\Test\TestComponent.cshtml)
Expand All @@ -14,7 +14,7 @@ Source Location: (50:1,7 [105] x:\dir\subdir\Test\TestComponent.cshtml)

public string nameof(string s) => string.Empty;
|
Generated Location: (2081:62,7 [105] )
Generated Location: (2089:62,7 [105] )
|
public int ParentValue { get; set; } = 42;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.
#line hidden
#nullable disable
);
__o = new global::System.Action<System.Int32>(
__o = new global::System.Action<global::System.Int32>(
__value => ParentValue = __value);
__builder.AddAttribute(-1, "ChildContent", (global::Microsoft.AspNetCore.Components.RenderFragment)((__builder2) => {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ Generated Location: (1135:29,26 [11] )

Source Location: (19:0,19 [5] x:\dir\subdir\Test\TestComponent.cshtml)
|Value|
Generated Location: (1668:44,19 [5] )
Generated Location: (1676:44,19 [5] )
|Value|

Source Location: (50:1,7 [55] x:\dir\subdir\Test\TestComponent.cshtml)
|
public string ParentValue { get; set; } = "42";
|
Generated Location: (2081:62,7 [55] )
Generated Location: (2089:62,7 [55] )
|
public string ParentValue { get; set; } = "42";
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.
#line hidden
#nullable disable
);
__o = new global::System.Action<System.Int32>(
__o = new global::System.Action<global::System.Int32>(
__value => { ParentValue = __value; global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.InvokeSynchronousDelegate(
#nullable restore
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ Generated Location: (1139:29,30 [11] )

Source Location: (62:0,62 [6] x:\dir\subdir\Test\TestComponent.cshtml)
|Update|
Generated Location: (1559:39,62 [6] )
Generated Location: (1567:39,62 [6] )
|Update|

Source Location: (19:0,19 [5] x:\dir\subdir\Test\TestComponent.cshtml)
|Value|
Generated Location: (1983:52,19 [5] )
Generated Location: (1991:52,19 [5] )
|Value|

Source Location: (49:0,49 [5] x:\dir\subdir\Test\TestComponent.cshtml)
|Value|
Generated Location: (2234:61,49 [5] )
Generated Location: (2242:61,49 [5] )
|Value|

Source Location: (81:1,7 [82] x:\dir\subdir\Test\TestComponent.cshtml)
Expand All @@ -24,7 +24,7 @@ Source Location: (81:1,7 [82] x:\dir\subdir\Test\TestComponent.cshtml)

public void Update() { }
|
Generated Location: (2647:79,7 [82] )
Generated Location: (2655:79,7 [82] )
|
public int ParentValue { get; set; } = 42;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.
#line hidden
#nullable disable
);
__o = new global::System.Action<System.Int32>(
__o = new global::System.Action<global::System.Int32>(
__value => { ParentValue = __value; global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.InvokeSynchronousDelegate(
#nullable restore
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ Generated Location: (1139:29,30 [11] )

Source Location: (62:0,62 [9] x:\dir\subdir\Test\TestComponent.cshtml)
|() => { }|
Generated Location: (1559:39,62 [9] )
Generated Location: (1567:39,62 [9] )
|() => { }|

Source Location: (19:0,19 [5] x:\dir\subdir\Test\TestComponent.cshtml)
|Value|
Generated Location: (1986:52,19 [5] )
Generated Location: (1994:52,19 [5] )
|Value|

Source Location: (49:0,49 [5] x:\dir\subdir\Test\TestComponent.cshtml)
|Value|
Generated Location: (2237:61,49 [5] )
Generated Location: (2245:61,49 [5] )
|Value|

Source Location: (84:1,7 [50] x:\dir\subdir\Test\TestComponent.cshtml)
|
public int ParentValue { get; set; } = 42;
|
Generated Location: (2650:79,7 [50] )
Generated Location: (2658:79,7 [50] )
|
public int ParentValue { get; set; } = 42;
|
Expand Down
Loading