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

Compiler error with new using pattern #33746

Closed
tomrus88 opened this issue Feb 28, 2019 · 3 comments
Closed

Compiler error with new using pattern #33746

tomrus88 opened this issue Feb 28, 2019 · 3 comments
Assignees
Labels
Area-Compilers Bug Concept-Diagnostic Clarity The issues deals with the ease of understanding of errors and warnings. Feature - enhanced using Using pattern and declaration
Milestone

Comments

@tomrus88
Copy link

tomrus88 commented Feb 28, 2019

Version Used:
VS 16.0.0 Preview 4.0

Steps to Reproduce:

class Test
{
    public void Dispose()
    {

    }
}

using (var t = new Test()) // Error CS1674
{

}

Expected Behavior:
No compiler error?

Actual Behavior:
Compiler error: Error CS1674 'Test': type used in a using statement must be implicitly convertible to 'System.IDisposable' or implement a suitable 'Dispose' method.

Not sure what's intended behavior... If everything is working as intended, then error message is misleading...

According to dotnet/csharplang#1623

This proposal is allow any type which structurally matches IDisposable (has a public void-returning non-generic instance method taking no arguments) to be used in a using statement.

this is a bug...

@gafter
Copy link
Member

gafter commented Feb 28, 2019

I believe there has been a spec change not reflected in the spec or diagnostic.

@gafter gafter added this to the 16.1.P1 milestone Feb 28, 2019
@gafter gafter added the Feature - Range Range label Feb 28, 2019
@gafter gafter modified the milestones: 16.1.P1, 16.1.P3 Apr 9, 2019
@jcouv jcouv modified the milestones: 16.1.P3, 16.1, 16.2 Apr 18, 2019
@jcouv jcouv added the Concept-Diagnostic Clarity The issues deals with the ease of understanding of errors and warnings. label Jun 19, 2019
@jcouv
Copy link
Member

jcouv commented Jun 19, 2019

The diagnostic message should be updated.
Pattern-based disposal is only supported on ref structs. Otherwise, it would affect existing code (foreach where the enumerator type happens to have a Dispose() method would now start calling that method).

@jcouv jcouv modified the milestones: 16.2, 16.3 Jun 19, 2019
@jcouv
Copy link
Member

jcouv commented Jul 11, 2019

This is a message tweak

@chsienki chsienki added Feature - enhanced using Using pattern and declaration and removed Feature - Range Range labels Jul 11, 2019
@jcouv jcouv modified the milestones: 16.3, Compiler.Next Jul 17, 2019
bgrainger added a commit to bgrainger/roslyn that referenced this issue Oct 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Bug Concept-Diagnostic Clarity The issues deals with the ease of understanding of errors and warnings. Feature - enhanced using Using pattern and declaration
Projects
None yet
Development

No branches or pull requests

4 participants