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

Support static constructors in interfaces #33625

Conversation

AlekseyTs
Copy link
Contributor

No description provided.

@AlekseyTs AlekseyTs requested a review from a team as a code owner February 23, 2019 01:08
@AlekseyTs
Copy link
Contributor Author

@dotnet/roslyn-compiler Please review

2 similar comments
@AlekseyTs
Copy link
Contributor Author

@dotnet/roslyn-compiler Please review

@AlekseyTs
Copy link
Contributor Author

@dotnet/roslyn-compiler Please review

@jaredpar
Copy link
Member

Reviewing


compilation1.VerifyDiagnostics();

CompileAndVerify(compilation1, expectedOutput: !CoreClrShim.IsRunningOnCoreClr ? null : "I1.I1", verify: VerifyOnCoreClr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The runtime has facilities for dealing with cyclic static constructors on classes / structs. The behavior should be the same for interfaces (largely undefined ordering but executes without crashing). Think we should add one sanity test here just to ensure they have hooked up this code path.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The runtime has facilities for dealing with cyclic static constructors on classes / structs. The behavior should be the same for interfaces (largely undefined ordering but executes without crashing). Think we should add one sanity test here just to ensure they have hooked up this code path.

Sure, let's discuss offline what you have in mind in more details.


In reply to: 260422959 [](ancestors = 260422959)

Copy link
Member

@jaredpar jaredpar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

parseOptions: TestOptions.Regular7_3);

compilation1.VerifyDiagnostics(
// (4,12): error CS8652: The feature 'default interface implementation' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.
Copy link
Member

@333fred 333fred Feb 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: is there any way to suppress this error? Otherwise, when we eventually ship C# 8.0, this error will need to be deleted from this test and who knows how many others. #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: is there any way to suppress this error? Otherwise, when we eventually ship C# 8.0, this error will need to be deleted from this test and who knows how many others.

It is the purpose of the test to verify presence of this diagnostics. The error will never go away for the scenario, the wording might change though, but that is due to the "Preview" mode ending.


In reply to: 260427140 [](ancestors = 260427140)

// I1(){}
Diagnostic(ErrorCode.ERR_InterfacesCantContainConstructors, "I1").WithLocation(4, 5),
// (6,12): error CS0526: Interfaces cannot contain constructors
// (10,5): error CS0501: 'I2.I2()' must declare a body because it is not marked abstract, extern, or partial
Copy link
Member

@333fred 333fred Feb 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we suppress this error if CS0526 is reported? This error doesn't matter: whether or not the interface constructor has a body is irrelevant. It's illegal either way. #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not believe it is worth it.


In reply to: 260428025 [](ancestors = 260428025)


validate(compilation1.SourceModule);

void validate(ModuleSymbol m)
Copy link
Member

@333fred 333fred Feb 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: local method seems unnecessary. If you want to keep it, please move to the end of the function. #Pending

Copy link
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (commit 1). One minor outstanding nit that can be addressed in a follow up.

@AlekseyTs AlekseyTs merged commit 6d56935 into dotnet:features/DefaultInterfaceImplementation Feb 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants