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

Invalid Code Generation & Potential Parsing Error #62997

Closed
TonyValenti opened this issue Jul 27, 2022 · 2 comments
Closed

Invalid Code Generation & Potential Parsing Error #62997

TonyValenti opened this issue Jul 27, 2022 · 2 comments

Comments

@TonyValenti
Copy link

Version Used:
VS 17.2.6

Steps to Reproduce:

  1. Write this code:
public class Foo {
    protected virtual T? Serialization_Remove<T>(string Value) {
        return default;
    }
}

public class Foo1 : Foo {

}
  1. Then go inside Foo1 and type override ser and press TAB and then Foo1 will have the following code:
public class Foo1 : Foo {

    protected override T? Serialization_Remove<T>(string Value) {
        return base.Serialization_Remove<T>(Value);
    }

}
  1. The auto-generated code does not compile! Oddly, however, altering the code as follows causes it to work:
public class Foo1 : Foo {
    protected override T? Serialization_Remove<T>(string Value) where T : default { // Note the new where clause here
        return base.Serialization_Remove<T>(Value);
    }
}

Expected Behavior:
I believe there are two separate-but-related issues.

Issue 1
2. According to the docs the where T : default is necessary ...when a base class or interface declares two overloads of a method, one that specifies the struct constraint, and one that doesn't have either the struct or class constraint applied, however, as you see in the code above, there are not two overloads of a method. Because of this, I believe that the T : default should not be necessary.

Issue 2
The auto-generated code does not work. It should, regardless of how Issue1 is dealt with.

Actual Behavior:
Auto-generated code should work; ideally without needing the T : default constraint.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Jul 27, 2022
@Youssef1313
Copy link
Member

Youssef1313 commented Jul 28, 2022

I think the compiler behavior is by-design (see #53713 (comment)), there is a suggestion for a better error message in #46458

The IDE completion behavior is probably a bug (similar to (but different from) #53012), I think.

@vatsalyaagrawal vatsalyaagrawal added Bug Investigation Required and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Jul 28, 2022
@vatsalyaagrawal vatsalyaagrawal added this to the Backlog milestone Jul 28, 2022
@CyrusNajmabadi
Copy link
Member

This was fixed. We now generate:

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants