dotnet / dotnet/csharpstandard

Specification does not forbid conditional methods with out parameters

Open
#286 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
815
Forks
99
Avg merge
1d 14h
Merged PRs (30d)
16

Description

The [Conditional methods](https://github.com/dotnet/csharplang/blob/cd7964e/spec/attributes.md#conditional-methods) section of the spec says:

> A conditional method is subject to the following restrictions:
>
> * The conditional method must be a method in a *class_declaration* or *struct_declaration*. A compile-time error occurs if the `Conditional` attribute is specified on a method in an interface declaration.
> * The conditional method must have a return type of `void`.
> * The conditional method must not be marked with the `override` modifier. A conditional method may be marked with the `virtual` modifier, however. Overrides of such a method are implicitly conditional, and must not be explicitly marked with a `Conditional` attribute.
> * The conditional method must not be an implementation of an interface method. Otherwise, a compile-time error occurs.

It does not say anything about `out` parameters and yet the compiler does not allow them. [This code](https://tryroslyn.azurewebsites.net/#f:r/K4Zwlgdg5gBAygTxAFwKYFsB0ARMBDKCAexTAGMQBuAWACgAHYAIwBtyYyW8QQYBhGAG86MUTADafIhAAmYZGGl4WACgBE2AKIAhAKoBxNQEoAuiLEA3ImBkwAsiqLBkMSC7BGhAXzpegA==):

```c#
using System.Diagnostics;
public class C {
[Conditional("DEBUG")]
void M(out int i) {}
}
```

Produces:

> error CS0685: Conditional member 'C.M(out int)' cannot have an out parameter

Considering that the error makes sense and that the somewhat similar `partial` methods [do prohibit `out` parameters](https://github.com/dotnet/csharplang/blob/6027ad5a4ab013f4fb42f5edd2d667d649fe1bd8/spec/classes.md#partial-methods) in the spec, I think the specification should be change to include this restriction.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.