Skip to content

Commit 370c3a5

Browse files
committed
Fix for OAPH nullability for reference types
Added Nested Project test to prove inheritance can operate
1 parent 954ab78 commit 370c3a5

File tree

9 files changed

+136
-5
lines changed

9 files changed

+136
-5
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved.
2+
// Licensed to the .NET Foundation under one or more agreements.
3+
// The .NET Foundation licenses this file to you under the MIT license.
4+
// See the LICENSE file in the project root for full license information.
5+
6+
using ReactiveUI;
7+
using ReactiveUI.SourceGenerators;
8+
9+
namespace SGReactiveUI.SourceGenerators.Execute.Nested1;
10+
11+
/// <summary>
12+
/// Class1.
13+
/// </summary>
14+
public partial class Class1 : ReactiveObject
15+
{
16+
[Reactive]
17+
private string? _property1;
18+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<ProjectReference Include="..\ReactiveUI.SourceGenerators\ReactiveUI.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="all" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<PackageReference Include="ReactiveUI" />
15+
</ItemGroup>
16+
17+
</Project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved.
2+
// Licensed to the .NET Foundation under one or more agreements.
3+
// The .NET Foundation licenses this file to you under the MIT license.
4+
// See the LICENSE file in the project root for full license information.
5+
6+
using ReactiveUI;
7+
using ReactiveUI.SourceGenerators;
8+
9+
namespace SGReactiveUI.SourceGenerators.Execute.Nested2;
10+
11+
/// <summary>
12+
/// Class1.
13+
/// </summary>
14+
public partial class Class1 : ReactiveObject
15+
{
16+
[Reactive]
17+
private string? _property1;
18+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<ProjectReference Include="..\ReactiveUI.SourceGenerators\ReactiveUI.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="all" />
11+
<ProjectReference Include="..\ReactiveUI.SourceGenerators.Execute.Nested1\ReactiveUI.SourceGenerators.Execute.Nested1.csproj" />
12+
</ItemGroup>
13+
14+
</Project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved.
2+
// Licensed to the .NET Foundation under one or more agreements.
3+
// The .NET Foundation licenses this file to you under the MIT license.
4+
// See the LICENSE file in the project root for full license information.
5+
6+
using ReactiveUI;
7+
using ReactiveUI.SourceGenerators;
8+
9+
namespace SGReactiveUI.SourceGenerators.Execute.Nested3;
10+
11+
/// <summary>
12+
/// Class1.
13+
/// </summary>
14+
public partial class Class1 : ReactiveObject
15+
{
16+
[Reactive]
17+
private string? _property1;
18+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<IsPackable>false</IsPackable>
8+
<LangVersion>12.0</LangVersion>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<ProjectReference Include="..\ReactiveUI.SourceGenerators\ReactiveUI.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="all" />
13+
<ProjectReference Include="..\ReactiveUI.SourceGenerators.Execute.Nested2\ReactiveUI.SourceGenerators.Execute.Nested2.csproj" />
14+
</ItemGroup>
15+
16+
</Project>

src/ReactiveUI.SourceGenerators.Execute/TestViewModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,12 @@ public TestViewModel()
234234
/// </summary>
235235
public ViewModelActivator Activator { get; } = new();
236236

237+
[ObservableAsProperty]
238+
private IObservable<object> ReferenceTypeObservable { get; }
239+
240+
[ObservableAsProperty]
241+
private IObservable<object?> NullableReferenceTypeObservable { get; }
242+
237243
/// <summary>
238244
/// Gets observables as property test.
239245
/// </summary>

src/ReactiveUI.SourceGenerators.sln

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Microsoft Visual Studio Solution File, Format Version 12.00
2-
# Visual Studio Version 17
2+
# 17
33
VisualStudioVersion = 17.10.35027.167
44
MinimumVisualStudioVersion = 10.0.40219.1
55
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionConfig", "SolutionConfig", "{F29AF2F3-DEC8-58BC-043A-1447862C832D}"
@@ -26,6 +26,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestLibs", "TestLibs", "{B8
2626
EndProject
2727
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReactiveUI.SourceGenerators.Analyzers.CodeFixes", "ReactiveUI.SourceGenerators.Analyzers.CodeFixes\ReactiveUI.SourceGenerators.Analyzers.CodeFixes.csproj", "{BD4FADD9-C0E5-46E9-906E-01B04CC856B5}"
2828
EndProject
29+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReactiveUI.SourceGenerators.Execute.Nested1", "ReactiveUI.SourceGenerators.Execute.Nested1\ReactiveUI.SourceGenerators.Execute.Nested1.csproj", "{A4971B7D-E35F-4891-BF32-BE911AE86900}"
30+
EndProject
31+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReactiveUI.SourceGenerators.Execute.Nested2", "ReactiveUI.SourceGenerators.Execute.Nested2\ReactiveUI.SourceGenerators.Execute.Nested2.csproj", "{CB36161E-8F9E-48B5-8CE0-AC130A73BD2A}"
32+
EndProject
33+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReactiveUI.SourceGenerators.Execute.Nested3", "ReactiveUI.SourceGenerators.Execute.Nested3\ReactiveUI.SourceGenerators.Execute.Nested3.csproj", "{B42F683D-91D8-4378-9DFE-EC55DB0FE43A}"
34+
EndProject
35+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NestedTest", "NestedTest", "{CAFBD27B-5078-4A0C-A4E9-19DCF2A7DF16}"
36+
EndProject
2937
Global
3038
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3139
Debug|Any CPU = Debug|Any CPU
@@ -52,13 +60,29 @@ Global
5260
{BD4FADD9-C0E5-46E9-906E-01B04CC856B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
5361
{BD4FADD9-C0E5-46E9-906E-01B04CC856B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
5462
{BD4FADD9-C0E5-46E9-906E-01B04CC856B5}.Release|Any CPU.Build.0 = Release|Any CPU
63+
{A4971B7D-E35F-4891-BF32-BE911AE86900}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
64+
{A4971B7D-E35F-4891-BF32-BE911AE86900}.Debug|Any CPU.Build.0 = Debug|Any CPU
65+
{A4971B7D-E35F-4891-BF32-BE911AE86900}.Release|Any CPU.ActiveCfg = Release|Any CPU
66+
{A4971B7D-E35F-4891-BF32-BE911AE86900}.Release|Any CPU.Build.0 = Release|Any CPU
67+
{CB36161E-8F9E-48B5-8CE0-AC130A73BD2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
68+
{CB36161E-8F9E-48B5-8CE0-AC130A73BD2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
69+
{CB36161E-8F9E-48B5-8CE0-AC130A73BD2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
70+
{CB36161E-8F9E-48B5-8CE0-AC130A73BD2A}.Release|Any CPU.Build.0 = Release|Any CPU
71+
{B42F683D-91D8-4378-9DFE-EC55DB0FE43A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
72+
{B42F683D-91D8-4378-9DFE-EC55DB0FE43A}.Debug|Any CPU.Build.0 = Debug|Any CPU
73+
{B42F683D-91D8-4378-9DFE-EC55DB0FE43A}.Release|Any CPU.ActiveCfg = Release|Any CPU
74+
{B42F683D-91D8-4378-9DFE-EC55DB0FE43A}.Release|Any CPU.Build.0 = Release|Any CPU
5575
EndGlobalSection
5676
GlobalSection(SolutionProperties) = preSolution
5777
HideSolutionNode = FALSE
5878
EndGlobalSection
5979
GlobalSection(NestedProjects) = preSolution
6080
{76D5AC8C-4935-3E4B-BD12-71FAEC2B9A9D} = {B86ED9C1-AFFB-4854-AD80-F4B4050CAD0A}
6181
{849CACF4-B85F-47B5-84B3-7C94DE864E7E} = {B86ED9C1-AFFB-4854-AD80-F4B4050CAD0A}
82+
{A4971B7D-E35F-4891-BF32-BE911AE86900} = {CAFBD27B-5078-4A0C-A4E9-19DCF2A7DF16}
83+
{CB36161E-8F9E-48B5-8CE0-AC130A73BD2A} = {CAFBD27B-5078-4A0C-A4E9-19DCF2A7DF16}
84+
{B42F683D-91D8-4378-9DFE-EC55DB0FE43A} = {CAFBD27B-5078-4A0C-A4E9-19DCF2A7DF16}
85+
{CAFBD27B-5078-4A0C-A4E9-19DCF2A7DF16} = {B86ED9C1-AFFB-4854-AD80-F4B4050CAD0A}
6286
EndGlobalSection
6387
GlobalSection(ExtensibilityGlobals) = postSolution
6488
SolutionGuid = {173F891B-86A2-4226-B563-A7318CE0E2EC}

src/ReactiveUI.SourceGenerators/ObservableAsProperty/ObservableAsPropertyGenerator{FromObservable}.Execute.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public sealed partial class ObservableAsPropertyGenerator
6464

6565
var observableType = methodSymbol.ReturnType is not INamedTypeSymbol typeSymbol
6666
? string.Empty
67-
: typeSymbol.TypeArguments[0].ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
67+
: typeSymbol.TypeArguments[0].GetFullyQualifiedNameWithNullabilityAnnotations();
6868

6969
// Get the hierarchy info for the target symbol, and try to gather the property info
7070
hierarchy = HierarchyInfo.From(methodSymbol.ContainingType);
@@ -82,7 +82,7 @@ public sealed partial class ObservableAsPropertyGenerator
8282
targetInfo.TargetVisibility,
8383
targetInfo.TargetType,
8484
methodSymbol.Name,
85-
methodSymbol.ReturnType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
85+
methodSymbol.ReturnType.GetFullyQualifiedNameWithNullabilityAnnotations(),
8686
methodSymbol.Parameters.FirstOrDefault()?.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
8787
propertyName ?? (methodSymbol.Name + "Property"),
8888
observableType,
@@ -109,7 +109,7 @@ public sealed partial class ObservableAsPropertyGenerator
109109

110110
var observableType = propertySymbol.Type is not INamedTypeSymbol typeSymbol
111111
? string.Empty
112-
: typeSymbol.TypeArguments[0].ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
112+
: typeSymbol.TypeArguments[0].GetFullyQualifiedNameWithNullabilityAnnotations();
113113

114114
// Get the hierarchy info for the target symbol, and try to gather the property info
115115
hierarchy = HierarchyInfo.From(propertySymbol.ContainingType);
@@ -127,7 +127,7 @@ public sealed partial class ObservableAsPropertyGenerator
127127
targetInfo.TargetVisibility,
128128
targetInfo.TargetType,
129129
propertySymbol.Name,
130-
propertySymbol.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
130+
propertySymbol.Type.GetFullyQualifiedNameWithNullabilityAnnotations(),
131131
propertySymbol.Parameters.FirstOrDefault()?.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
132132
propertyName ?? (propertySymbol.Name + "Property"),
133133
observableType,

0 commit comments

Comments
 (0)