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

MVVM Source Generators: ObservablePropertyAttribute on member var named value #4216

Closed
21 tasks
Rosuavio opened this issue Sep 1, 2021 · 1 comment · Fixed by #4219
Closed
21 tasks

MVVM Source Generators: ObservablePropertyAttribute on member var named value #4216

Rosuavio opened this issue Sep 1, 2021 · 1 comment · Fixed by #4219
Assignees
Labels
bug 🐛 An unexpected issue that highlights incorrect behavior Completed 🔥 mvvm-toolkit 🧰 Issues/PRs for the Microsoft.Toolkit.Mvvm package
Milestone

Comments

@Rosuavio
Copy link
Contributor

Rosuavio commented Sep 1, 2021

Describe the bug

If you put the ObservablePropertyAttribute on a member var named value it successfully generates a source code for a property that does reference the member variable named value in the generated code as intended. Instead the member var named value gets shadowed by the property setter key word value and the value from the setter gets compared with its self and the member var does not get updated.

  • Is this bug a regression in the toolkit? If so, what toolkit version did you last see it work:

Steps to Reproduce

  • Can this be reproduced in the Sample App? (Either in a sample as-is or with new XAML pasted in the editor.) If so, please provide custom XAML or steps to reproduce. If not, let us know why it can't be reproduced (e.g. more complex setup, environment, dependencies, etc...)

Steps to reproduce the behavior:

  1. Created a project where you can use the source generators (netstandard)
  2. Add the Mvvm package.
  3. Write this class
[ObservableObject]
    public partial class Class1
    {
        [ObservableProperty]
        private int value;
    }
  1. See this generated code
[global::System.CodeDom.Compiler.GeneratedCode("Microsoft.Toolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "7.1.0.0")]
        [global::System.Diagnostics.DebuggerNonUserCode]
        [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
        public string Value
        {
            get => value;
            set
            {
                if (!global::System.Collections.Generic.EqualityComparer<string>.Default.Equals(value, value))
                {
                    OnPropertyChanging(global::Microsoft.Toolkit.Mvvm.ComponentModel.__Internals.__KnownINotifyPropertyChangedOrChangingArgs.ValuePropertyChangingEventArgs);
                    value = value;
                    OnPropertyChanged(global::Microsoft.Toolkit.Mvvm.ComponentModel.__Internals.__KnownINotifyPropertyChangedOrChangingArgs.ValuePropertyChangedEventArgs);
                }
            }
        }

Expected behavior

The member var value and any other keywords in the context of the generated code that could be names of vars are distinguished from keywords in the contexts of the the generated code, or something warns or errors out before such code can be compiled and/or ran, so that users of the generators are not caught off guard with a sneaky error.

Screenshots

Environment

NuGet Package(s):

Package Version(s):

Windows 10 Build Number:

  • Fall Creators Update (16299)
  • April 2018 Update (17134)
  • October 2018 Update (17763)
  • May 2019 Update (18362)
  • May 2020 Update (19041)
  • Insider Build ({build_number})

App min and target version:

  • Fall Creators Update (16299)
  • April 2018 Update (17134)
  • October 2018 Update (17763)
  • May 2019 Update (18362)
  • May 2020 Update (19041)
  • Insider Build ({build_number})

Device form factor:

  • Desktop
  • Xbox
  • Surface Hub
  • IoT

Visual Studio version:

  • 2017 (15.{minor_version})
  • 2019 (16.{minor_version})
  • 2022 (17.{minor_version})

Additional context

@Rosuavio Rosuavio added bug 🐛 An unexpected issue that highlights incorrect behavior mvvm-toolkit 🧰 Issues/PRs for the Microsoft.Toolkit.Mvvm package labels Sep 1, 2021
@Rosuavio Rosuavio added this to the 7.1 milestone Sep 1, 2021
@Sergio0694
Copy link
Member

Oh, whoops! I forgot to add this. here, good catch! 😄
Should be an easy fix at least!

@ghost ghost added the In-PR 🚀 label Sep 2, 2021
@ghost ghost added Completed 🔥 and removed In-PR 🚀 labels Sep 2, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Nov 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug 🐛 An unexpected issue that highlights incorrect behavior Completed 🔥 mvvm-toolkit 🧰 Issues/PRs for the Microsoft.Toolkit.Mvvm package
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants