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: CS1038 Error if [ObservableProperty] attribute is in a #region block #4225

Closed
6 of 21 tasks
JasonWei512 opened this issue Sep 3, 2021 · 2 comments · Fixed by #4227
Closed
6 of 21 tasks
Assignees
Labels
bug 🐛 An unexpected issue that highlights incorrect behavior Completed 🔥 mvvm-toolkit 🧰 Issues/PRs for the Microsoft.Toolkit.Mvvm package sdkcheck 🏁
Milestone

Comments

@JasonWei512
Copy link

JasonWei512 commented Sep 3, 2021

Describe the bug

Compilation fails If the Microsoft MVVM Toolkit source generator attribute [ObservableProperty] is in a #region block.

  • 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...)

Sample project:

https://github.com/JasonWei512/MicrosoftMvvmToolkitSourceGeneratorBug

Steps to reproduce the behavior:

When compiling the following code, you will get a "CS1038 #endregion directive expected" error:

// Doesn't compile

#region Properties

[ObservableProperty]
private int counter = 0;

#endregion

If you delete the #region Properties and #endregion lines, the code will compile:

// Compiles

// #region Properties

[ObservableProperty]
private int counter = 0;

// #endregion

Expected behavior

The code should compile.

Screenshots

None.

Environment

NuGet Package(s):

  • Microsoft.Toolkit.Mvvm

Package Version(s):

  • 7.1.0-rc1

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 (22000.168)

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

None.

@JasonWei512 JasonWei512 added the bug 🐛 An unexpected issue that highlights incorrect behavior label Sep 3, 2021
@ghost ghost added the needs triage 🔍 label Sep 3, 2021
@ghost
Copy link

ghost commented Sep 3, 2021

Hello JasonWei512, thank you for opening an issue with us!

I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌

@michael-hawker
Copy link
Member

michael-hawker commented Sep 3, 2021

Nice find, thanks @JasonWei512!

FYI @Sergio0694

@michael-hawker michael-hawker added mvvm-toolkit 🧰 Issues/PRs for the Microsoft.Toolkit.Mvvm package and removed needs triage 🔍 labels Sep 3, 2021
@michael-hawker michael-hawker added this to the 7.1 milestone Sep 3, 2021
@ghost ghost closed this as completed in #4227 Sep 16, 2021
ghost pushed a commit that referenced this issue Sep 16, 2021
<!-- 🚨 Please Do Not skip any instructions and information mentioned below as they are all required and essential to evaluate and test the PR. By fulfilling all the required information you will be able to reduce the volume of questions and most likely help merge the PR faster 🚨 -->

<!-- 👉 It is imperative to resolve ONE ISSUE PER PR and avoid making multiple changes unless the changes interrelate with each other -->

<!-- 📝 Please always keep the "☑️ Allow edits by maintainers" button checked in the Pull Request Template as it increases collaboration with the Toolkit maintainers by permitting commits to your PR branch (only) created from your fork. This can let us quickly make fixes for minor typos or forgotten StyleCop issues during review without needing to wait on you doing extra work. Let us help you help us! 🎉 -->

## Fixes #4225

<!-- Add the relevant issue number after the word "Fixes" mentioned above (for ex: "## Fixes #1234") which will automatically close the issue once the PR is merged. -->

<!-- Add a brief overview here of the feature/bug & fix. -->

## PR Type

What kind of change does this PR introduce?

<!-- Please uncomment one or more options below that apply to this PR. -->

- Bugfix
<!-- - Feature -->
<!-- - Code style update (formatting) -->
<!-- - Refactoring (no functional changes, no api changes) -->
<!-- - Build or CI related changes -->
<!-- - Documentation content changes -->
<!-- - Sample app changes -->
<!-- - Other... Please describe: -->

## What is the current behavior?
Compilation fails If the Microsoft MVVM Toolkit source generator attribute `[ObservableProperty]` is in a `#region` block.
<!-- Please describe the current behavior that you are modifying, or link to a relevant issue. -->

## What is the new behavior?
The generated code is now correct when regions are used.
<!-- Describe how was this issue resolved or changed? -->

## PR Checklist

Please check if your PR fulfills the following requirements: <!-- and remove the ones that are not applicable to the current PR -->

- [X] Tested code with current [supported SDKs](../#supported)
- [X] New component
  - [X] Pull Request has been submitted to the documentation repository [instructions](../blob/main/Contributing.md#docs). Link: <!-- docs PR link -->
  - [X] Added description of major feature to project description for NuGet package (4000 total character limit, so don't push entire description over that)
  - [X] If control, added to Visual Studio Design project
- [X] Sample in sample app has been added / updated (for bug fixes / features)
  - [X] Icon has been created (if new sample) following the [Thumbnail Style Guide and templates](https://github.com/CommunityToolkit/WindowsCommunityToolkit-design-assets)
- [X] New major technical changes in the toolkit have or will be added to the [Wiki](https://github.com/CommunityToolkit/WindowsCommunityToolkit/wiki) e.g. build changes, source generators, testing infrastructure, sample creation changes, etc...
- [X] Tests for the changes have been added (for bug fixes / features) (if applicable)
- [X] Header has been added to all new source files (run _build/UpdateHeaders.bat_)
- [X] Contains **NO** breaking changes
@ghost ghost added the Completed 🔥 label Sep 16, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Nov 15, 2021
This issue was closed.
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 sdkcheck 🏁
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants