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

Need annotation for nullable property with non-nullable setter #26621

Closed
jcouv opened this issue May 4, 2018 · 2 comments
Closed

Need annotation for nullable property with non-nullable setter #26621

jcouv opened this issue May 4, 2018 · 2 comments
Labels
Area-Compilers Area-Language Design Feature Request Need Design Review The end user experience design needs to be reviewed and approved. New Language Feature - Nullable Reference Types Nullable Reference Types
Milestone

Comments

@jcouv
Copy link
Member

jcouv commented May 4, 2018

Let's bring this up with LDM.

        public ITaskItem[]? Sources
        {
            set
            {
                if (UsedCommandLineTool)
                {
                    NormalizePaths(value!); // PROTOTYPE(NullableDogfood): value set should be non-null
                }

                _store[nameof(Sources)] = value;
            }
            get { return (ITaskItem[])_store[nameof(Sources)]; }
        }
@sharwell
Copy link
Member

sharwell commented May 9, 2018

💭 In most cases where I hit this so far, the property was able to be rewritten in this form. It doesn't work for everything but likely covers many.

public SomeType Property
{
  get => _value ?? throw new InvalidOperationException("The object is not yet initialized");
  set => _value = value;
}

@jcouv jcouv assigned jcouv and unassigned jcouv May 9, 2018
@jaredpar jaredpar added the Need Design Review The end user experience design needs to be reviewed and approved. label Jan 26, 2019
@jaredpar jaredpar modified the milestones: 16.0, 16.1.P1 Jan 26, 2019
@gafter gafter modified the milestones: 16.1.P1, 16.1.P3 Apr 9, 2019
@jaredpar jaredpar modified the milestones: 16.1.P3, Compiler.Next Apr 9, 2019
@jcouv
Copy link
Member Author

jcouv commented Jul 10, 2019

This was resolved by the new attribute design. We can restrict or relax inbound values with [Disallow/AllowNull] and restrict/relax outbound values with [Not/MaybeNull].

See https://github.com/dotnet/csharplang/blob/master/meetings/2019/LDM-2019-05-15.md

@jcouv jcouv closed this as completed Jul 10, 2019
@jcouv jcouv modified the milestones: Compiler.Next, 16.3 Jul 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Area-Language Design Feature Request Need Design Review The end user experience design needs to be reviewed and approved. New Language Feature - Nullable Reference Types Nullable Reference Types
Projects
None yet
Development

No branches or pull requests

4 participants