Open ericmutta opened 7 years ago
The C# language makes it an error to apply ConditionalAttribute
to an interface method. VB permits it but ignores it. I recommend we either respect the attribute, or warn about the application of the attribute in an interface. It is probably too late to make it an error.
@gafter The C# language makes it an error to apply ConditionalAttribute to an interface method.
Just out of curiosity...why is the attribute not honoured/allowed? Is there a technical reason?
@ericmutta No idea.
@gafter that's good news then, it means VB can go ahead and honour it since it already permits its application on interface methods 👍
For some context on why someone might want this (see code I gave earlier above):
I have a tracing interface used to write debugging information. In unattended test sessions I want tracing output to go to a file. In interactive test sessions I want tracing output to go to the console. So I had different trace recorders implement that interface. So far so good. When I switch to release build, I want the tracer interface calls to be removed completely (but that didn't happen despite the Conditional("DEBUG")
attribute - hence the bug report).
Version Used:
Visual Studio Community 2017 v15.3.3
Steps to Reproduce:
Type in the following code in VB console project:
If you run the above code in DEBUG build, it prints the following as expected:
If you run the code in RELEASE build, the compiler does not honour the
ConditionalAttribute
applied to the interface methodsThisHappened
andThatHappened
so the program mistakenly produces this output:Expected Behavior:
The MSDN ConditionalAttribute documentation says that it:
However the VB compiler doesn't honour that for these two method calls done via an interface variable:
Unless I have overlooked some (undocumented?) technical reason, I believe this is a bug.