Skip to content

[Bug]: required partial value type property emits code doesn't compile #237

Closed
@chsbuffer

Description

@chsbuffer

Describe the bug 🐞

Image

Step to reproduce

namespace MyNamespace
{
    public struct MyStruct;
    
    public partial class Foo : ReactiveObject
    {
        [Reactive(UseRequired = true)] 
        public required partial MyStruct StructProp { get; set; }

        [Reactive(UseRequired = true)] 
        public required partial long LongProp { get; set; }
    }
}

Reproduction repository

No response

Expected behavior

        if (propertyInfo.IncludeMemberNotNullOnSetAccessor || propertyInfo.IsReferenceTypeOrUnconstrainedTypeParameter)
        {
            return
$$"""
        {{fieldSyntax}}
        /// <inheritdoc cref="{{fieldName}}"/>
        {{propertyAttributes}}
        {{propertyInfo.TargetInfo.TargetVisibility}}{{propertyInfo.Inheritance}} {{propertyInfo.UseRequired}}{{partialModifier}}{{propertyInfo.TypeNameWithNullabilityAnnotations}} {{propertyInfo.PropertyName}}
        { 
            get => {{propertyInfo.FieldName}};
            [global::System.Diagnostics.CodeAnalysis.MemberNotNull("{{fieldName}}")]
            {{propertyInfo.AccessModifier}} => this.RaiseAndSetIfChanged(ref {{fieldName}}, value);
        }
""";
        }

        return
$$"""
        {{fieldSyntax}}
        /// <inheritdoc cref="{{fieldName}}"/>
        {{propertyAttributes}}
-        {{propertyInfo.TargetInfo.TargetVisibility}}{{propertyInfo.Inheritance}} {{partialModifier}}{{propertyInfo.UseRequired}}{{propertyInfo.TypeNameWithNullabilityAnnotations}} {{propertyInfo.PropertyName}} { get => {{propertyInfo.FieldName}}; {{propertyInfo.AccessModifier}} => this.RaiseAndSetIfChanged(ref {{fieldName}}, value); }
+        {{propertyInfo.TargetInfo.TargetVisibility}}{{propertyInfo.Inheritance}} {{propertyInfo.UseRequired}}{{partialModifier}}{{propertyInfo.TypeNameWithNullabilityAnnotations}} {{propertyInfo.PropertyName}} { get => {{propertyInfo.FieldName}}; {{propertyInfo.AccessModifier}} => this.RaiseAndSetIfChanged(ref {{fieldName}}, value); }
""";

Screenshots 🖼️

No response

IDE

No response

Operating system

No response

Version

No response

Device

No response

ReactiveUI Version

No response

Additional information ℹ️

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions