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

Add missing global:: prefix to type inference method parameters #8247

Merged
merged 5 commits into from
May 1, 2023
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 @@ -146,7 +146,7 @@ private void Process(ComponentIntermediateNode node)
var provideCascadingGenericTypes = new CascadingGenericTypeParameter
{
GenericTypeNames = typeParameters,
ValueType = attribute.BoundAttribute.TypeName,
ValueType = attribute.GloballyQualifiedTypeName,
ValueSourceNode = attribute,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6726,6 +6726,77 @@ public class Child<TOne, TTwo> : ComponentBase
CompileToAssembly(generated);
}

[Fact] // https://github.com/dotnet/razor/issues/7103
public void CascadingGenericInference_ParameterInNamespace()
{
// Arrange
AdditionalSyntaxTrees.Add(Parse("""
using Microsoft.AspNetCore.Components;

namespace MyApp
{
public class MyClass<T> { }
}

namespace MyApp.Components
{
[CascadingTypeParameter(nameof(T))]
public class ParentComponent<T> : ComponentBase
{
[Parameter] public MyApp.MyClass<T> Parameter { get; set; } = null!;
}

public class ChildComponent<T> : ComponentBase { }
}
"""));

// Act
var generated = CompileToCSharp("""
@namespace MyApp.Components

<ParentComponent Parameter="new MyClass<string>()">
<ChildComponent />
</ParentComponent>
""");

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

[Fact]
public void CascadingGenericInference_Tuple()
{
// Arrange
AdditionalSyntaxTrees.Add(Parse("""
using Microsoft.AspNetCore.Components;

namespace Test
{
[CascadingTypeParameter(nameof(T))]
public class ParentComponent<T> : ComponentBase
{
[Parameter] public (T, T) Parameter { get; set; }
}

public class ChildComponent<T> : ComponentBase { }
}
"""));

// Act
var generated = CompileToCSharp("""
<ParentComponent Parameter="(1, 2)">
<ChildComponent />
</ParentComponent>
""");

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

[Fact]
public void ChildComponent_GenericWeaklyTypedAttribute()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static void CreateGrid_0_CaptureParameters<TItem>(global::System.Collecti
{
__arg0_out = __arg0;
}
public static global::Test.Column<TItem> CreateColumn_1<TItem>(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq, System.Collections.Generic.IEnumerable<TItem> __syntheticArg0, int __seq0, global::Microsoft.AspNetCore.Components.RenderFragment<TItem> __arg0)
public static global::Test.Column<TItem> CreateColumn_1<TItem>(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq, global::System.Collections.Generic.IEnumerable<TItem> __syntheticArg0, int __seq0, global::Microsoft.AspNetCore.Components.RenderFragment<TItem> __arg0)
{
__builder.OpenComponent<global::Test.Column<TItem>>(seq);
__builder.AddComponentParameter(__seq0, "ChildContent", __arg0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public static void CreateGrid_0_CaptureParameters<TItem>(global::System.Collecti
{
__arg0_out = __arg0;
}
public static global::Test.Column<TItem, TOutput> CreateColumn_1<TItem, TOutput>(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq, System.Collections.Generic.IEnumerable<TItem> __syntheticArg0, int __seq0, global::System.Func<TItem, TOutput> __arg0)
public static global::Test.Column<TItem, TOutput> CreateColumn_1<TItem, TOutput>(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq, global::System.Collections.Generic.IEnumerable<TItem> __syntheticArg0, int __seq0, global::System.Func<TItem, TOutput> __arg0)
{
__builder.OpenComponent<global::Test.Column<TItem, TOutput>>(seq);
__builder.AddComponentParameter(__seq0, "SomeLambda", __arg0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static void CreateAncestor_0_CaptureParameters<TItem>(global::System.Coll
{
__arg0_out = __arg0;
}
public static global::Test.Child<TItem> CreateChild_1<TItem>(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq, System.Collections.Generic.IEnumerable<TItem> __syntheticArg0)
public static global::Test.Child<TItem> CreateChild_1<TItem>(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq, global::System.Collections.Generic.IEnumerable<TItem> __syntheticArg0)
{
__builder.OpenComponent<global::Test.Child<TItem>>(seq);
__builder.CloseComponent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static void CreateParent_0_CaptureParameters<TKey, TValue, TOther>(global
__arg0_out = __arg0;
__arg1_out = __arg1;
}
public static global::Test.Child<TOther, TValue, TKey, TChildOnly> CreateChild_1<TOther, TValue, TKey, TChildOnly>(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq, TOther __syntheticArg0, System.Collections.Generic.Dictionary<TKey, TValue> __syntheticArg1, System.Collections.Generic.Dictionary<TKey, TValue> __syntheticArg2, int __seq0, global::System.Collections.Generic.ICollection<TChildOnly> __arg0)
public static global::Test.Child<TOther, TValue, TKey, TChildOnly> CreateChild_1<TOther, TValue, TKey, TChildOnly>(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq, TOther __syntheticArg0, global::System.Collections.Generic.Dictionary<TKey, TValue> __syntheticArg1, global::System.Collections.Generic.Dictionary<TKey, TValue> __syntheticArg2, int __seq0, global::System.Collections.Generic.ICollection<TChildOnly> __arg0)
{
__builder.OpenComponent<global::Test.Child<TOther, TValue, TKey, TChildOnly>>(seq);
__builder.AddComponentParameter(__seq0, "ChildOnlyItems", __arg0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ public static void CreateGrid_0_CaptureParameters<TItem>(global::System.Collecti
{
__arg0_out = __arg0;
}
public static global::Test.Column<TItem> CreateColumn_1<TItem>(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq, System.Collections.Generic.IEnumerable<TItem> __syntheticArg0)
public static global::Test.Column<TItem> CreateColumn_1<TItem>(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq, global::System.Collections.Generic.IEnumerable<TItem> __syntheticArg0)
{
__builder.OpenComponent<global::Test.Column<TItem>>(seq);
__builder.CloseComponent();
return default;
}
public static global::Test.Column<TItem> CreateColumn_2<TItem>(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq, System.Collections.Generic.IEnumerable<TItem> __syntheticArg0)
public static global::Test.Column<TItem> CreateColumn_2<TItem>(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq, global::System.Collections.Generic.IEnumerable<TItem> __syntheticArg0)
{
__builder.OpenComponent<global::Test.Column<TItem>>(seq);
__builder.CloseComponent();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// <auto-generated/>
#pragma warning disable 1591
namespace MyApp.Components
{
#line hidden
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
((global::System.Action)(() => {
#nullable restore
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
global::System.Object __typeHelper = nameof(MyApp.Components);

#line default
#line hidden
#nullable disable
}
))();
}
#pragma warning restore 219
#pragma warning disable 0414
private static object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
{
{
global::__Blazor.MyApp.Components.TestComponent.TypeInference.CreateParentComponent_0_CaptureParameters(
#nullable restore
#line 3 "x:\dir\subdir\Test\TestComponent.cshtml"
new MyClass<string>()

#line default
#line hidden
#nullable disable
, out var __typeInferenceArg_0___arg0);
var __typeInference_CreateParentComponent_0 = global::__Blazor.MyApp.Components.TestComponent.TypeInference.CreateParentComponent_0(__builder, -1, -1, __typeInferenceArg_0___arg0, -1, (__builder2) => {
var __typeInference_CreateChildComponent_1 = global::__Blazor.MyApp.Components.TestComponent.TypeInference.CreateChildComponent_1(__builder2, -1, __typeInferenceArg_0___arg0);
#nullable restore
#line 4 "x:\dir\subdir\Test\TestComponent.cshtml"
__o = typeof(global::MyApp.Components.ChildComponent<>);

#line default
#line hidden
#nullable disable
}
);
#pragma warning disable BL0005
__typeInference_CreateParentComponent_0.
#nullable restore
#line 3 "x:\dir\subdir\Test\TestComponent.cshtml"
Parameter

#line default
#line hidden
#nullable disable
= default;
#pragma warning restore BL0005
}
#nullable restore
#line 3 "x:\dir\subdir\Test\TestComponent.cshtml"
__o = typeof(global::MyApp.Components.ParentComponent<>);

#line default
#line hidden
#nullable disable
}
#pragma warning restore 1998
}
}
namespace __Blazor.MyApp.Components.TestComponent
{
#line hidden
internal static class TypeInference
{
public static global::MyApp.Components.ParentComponent<T> CreateParentComponent_0<T>(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq, int __seq0, global::MyApp.MyClass<T> __arg0, int __seq1, Microsoft.AspNetCore.Components.RenderFragment __arg1)
{
__builder.OpenComponent<global::MyApp.Components.ParentComponent<T>>(seq);
__builder.AddComponentParameter(__seq0, "Parameter", __arg0);
__builder.AddComponentParameter(__seq1, "ChildContent", __arg1);
__builder.CloseComponent();
return default;
}

public static void CreateParentComponent_0_CaptureParameters<T>(global::MyApp.MyClass<T> __arg0, out global::MyApp.MyClass<T> __arg0_out)
{
__arg0_out = __arg0;
}
public static global::MyApp.Components.ChildComponent<T> CreateChildComponent_1<T>(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq, global::MyApp.MyClass<T> __syntheticArg0)
{
__builder.OpenComponent<global::MyApp.Components.ChildComponent<T>>(seq);
__builder.CloseComponent();
return default;
}
}
}
#pragma warning restore 1591
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Document -
NamespaceDeclaration - - MyApp.Components
UsingDirective - (3:1,1 [12] ) - System
UsingDirective - (18:2,1 [32] ) - System.Collections.Generic
UsingDirective - (53:3,1 [17] ) - System.Linq
UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks
UsingDirective - (104:5,1 [37] ) - Microsoft.AspNetCore.Components
ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase -
DesignTimeDirective -
DirectiveToken - (11:0,11 [16] x:\dir\subdir\Test\TestComponent.cshtml) - MyApp.Components
CSharpCode -
IntermediateToken - - CSharp - #pragma warning disable 0414
CSharpCode -
IntermediateToken - - CSharp - private static object __o = null;
CSharpCode -
IntermediateToken - - CSharp - #pragma warning restore 0414
MethodDeclaration - - protected override - void - BuildRenderTree
HtmlContent - (29:1,0 [2] x:\dir\subdir\Test\TestComponent.cshtml)
LazyIntermediateToken - (29:1,0 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n
Component - (31:2,0 [95] x:\dir\subdir\Test\TestComponent.cshtml) - ParentComponent
ComponentChildContent - - ChildContent - context
HtmlContent - (82:2,51 [6] x:\dir\subdir\Test\TestComponent.cshtml)
LazyIntermediateToken - (82:2,51 [6] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n
Component - (88:3,4 [18] x:\dir\subdir\Test\TestComponent.cshtml) - ChildComponent
HtmlContent - (106:3,22 [2] x:\dir\subdir\Test\TestComponent.cshtml)
LazyIntermediateToken - (106:3,22 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n
ComponentAttribute - (59:2,28 [21] x:\dir\subdir\Test\TestComponent.cshtml) - Parameter - Parameter - AttributeStructure.DoubleQuotes
LazyIntermediateToken - (59:2,28 [21] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - new MyClass<string>()
NamespaceDeclaration - - __Blazor.MyApp.Components.TestComponent
ClassDeclaration - - internal static - TypeInference - -
ComponentTypeInferenceMethod - - __Blazor.MyApp.Components.TestComponent.TypeInference - CreateParentComponent_0
ComponentTypeInferenceMethod - - __Blazor.MyApp.Components.TestComponent.TypeInference - CreateChildComponent_1
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Source Location: (11:0,11 [16] x:\dir\subdir\Test\TestComponent.cshtml)
|MyApp.Components|
Generated Location: (615:17,44 [16] )
|MyApp.Components|

Source Location: (59:2,28 [21] x:\dir\subdir\Test\TestComponent.cshtml)
|new MyClass<string>()|
Generated Location: (1290:36,28 [21] )
|new MyClass<string>()|

Source Location: (48:2,17 [9] x:\dir\subdir\Test\TestComponent.cshtml)
|Parameter|
Generated Location: (2246:57,17 [9] )
|Parameter|

Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// <auto-generated/>
#pragma warning disable 1591
namespace Test
{
#line hidden
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
}
#pragma warning restore 219
#pragma warning disable 0414
private static object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
{
{
global::__Blazor.Test.TestComponent.TypeInference.CreateParentComponent_0_CaptureParameters(
#nullable restore
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
(1, 2)

#line default
#line hidden
#nullable disable
, out var __typeInferenceArg_0___arg0);
var __typeInference_CreateParentComponent_0 = global::__Blazor.Test.TestComponent.TypeInference.CreateParentComponent_0(__builder, -1, -1, __typeInferenceArg_0___arg0, -1, (__builder2) => {
var __typeInference_CreateChildComponent_1 = global::__Blazor.Test.TestComponent.TypeInference.CreateChildComponent_1(__builder2, -1, __typeInferenceArg_0___arg0);
#nullable restore
#line 2 "x:\dir\subdir\Test\TestComponent.cshtml"
__o = typeof(global::Test.ChildComponent<>);

#line default
#line hidden
#nullable disable
}
);
#pragma warning disable BL0005
__typeInference_CreateParentComponent_0.
#nullable restore
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
Parameter

#line default
#line hidden
#nullable disable
= default;
#pragma warning restore BL0005
}
#nullable restore
#line 1 "x:\dir\subdir\Test\TestComponent.cshtml"
__o = typeof(global::Test.ParentComponent<>);

#line default
#line hidden
#nullable disable
}
#pragma warning restore 1998
}
}
namespace __Blazor.Test.TestComponent
{
#line hidden
internal static class TypeInference
{
public static global::Test.ParentComponent<T> CreateParentComponent_0<T>(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq, int __seq0, (T, T) __arg0, int __seq1, Microsoft.AspNetCore.Components.RenderFragment __arg1)
{
__builder.OpenComponent<global::Test.ParentComponent<T>>(seq);
__builder.AddComponentParameter(__seq0, "Parameter", __arg0);
__builder.AddComponentParameter(__seq1, "ChildContent", __arg1);
__builder.CloseComponent();
return default;
}

public static void CreateParentComponent_0_CaptureParameters<T>((T, T) __arg0, out (T, T) __arg0_out)
{
__arg0_out = __arg0;
}
public static global::Test.ChildComponent<T> CreateChildComponent_1<T>(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq, (T, T) __syntheticArg0)
{
__builder.OpenComponent<global::Test.ChildComponent<T>>(seq);
__builder.CloseComponent();
return default;
}
}
}
#pragma warning restore 1591
Loading