3

Recently, I've watched some videos about C# async bugs and got into discussions with friends.

Is it correct to say that a programming language has a bug ? or can you only say that a compiler has a bug ?

what is the difference between both ?

Attilah
  • 17,632
  • 38
  • 139
  • 202
  • 1
    Although it might be a interesting discussion I don't think this is really the place to discuss it. It will probably depend on what the bug is exactly. But I think a 'programming language' can not really have a bug in itself because it is just a syntax which is interpreted an rewritten by the compiler. So in my opinion the compiler will have the bug in most cases. – Gerald Versluis Aug 09 '12 at 11:50
  • [This](https://stackoverflow.com/questions/43736660/why-is-tryparse-in-c7-syntax-empty-out-parameter-emitting-a-warning-if-you-co) is an example of a bug I found in C#7, which was fixed later by the compiler team. And [that](https://stackoverflow.com/questions/41288668/why-is-a-local-function-not-always-hidden-in-c7) was something I thought it could be a bug in C#7 but turned out to be "as designed". – Matt Aug 10 '22 at 10:59

3 Answers3

7

The language has a design flaw if it's not designed well for whatever reason (e.g. the ability to call static methods via an expression of the declaring type in Java, IMO).

The language has a bug (IMO) if the specification is contradictory or doesn't express what the author intended it to express. (I believe there are some bugs in the C# language specification around type inference, for example.)

The compiler has a bug if it fails to implement the specification correctly.

EDIT: I've found an example of a spec bug which is rather simpler than type inference ones...

In the C# 4 spec, section 7.3.1 states: "Except for the assignment operators, all binary operators are left-associative".

Section 7.13 states: "The null coalescing operator is right-associative"

As the null coalescing operator is a non-assignment binary operator, this is a contradiction and thus (IMO) a bug. (It was also noted in this Stack Overflow question.)

The null coalescing operator also provides an example of a compiler bug which I discovered while answering that question...

Community
  • 1
  • 1
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • 1
    Can you point me to some links about the bug in the type inference or any other bugs in the C# language spec ? thanks – Attilah Aug 09 '12 at 11:52
  • @Attilah: I wanted to ask this same question. – Nikhil Agrawal Aug 09 '12 at 11:52
  • @Attilah: The details of the type inference section make my head hurt. I'll see if I can dredge up some other spec bugs though. – Jon Skeet Aug 09 '12 at 11:54
  • @JonSkeet: Would your question and Eric Lippert's answer contribute http://stackoverflow.com/questions/6256847/curious-null-coalescing-operator-custom-implicit-conversion-behaviour – Nikhil Agrawal Aug 09 '12 at 11:58
  • @Duane: Maybe a newbie in SO. Does not know who Jon Skeet is. – Nikhil Agrawal Aug 09 '12 at 11:59
  • 1
    @NikhilAgrawal I wasn't necessarily getting at that. It's more the fact that there's nothing wrong with the answer. – dtsg Aug 09 '12 at 12:04
  • @Jon Skeet, Thanks for the clarifications. did you file this as a bug for Microsoft to look at ? If so, link, please ? I'm learning a lot with you guyz. – Attilah Aug 09 '12 at 14:35
  • 1
    @Attilah: I mailed Eric Lippert, which is simpler for me :) – Jon Skeet Aug 09 '12 at 14:44
  • @JonSkeet: Thanks. Do you happen to know if they (Eric Lippert, Microsoft) consider this internally as an error or as a bug ? we are in the middle of an argument with colleagues as to whether to consider this type of error a bug or whether a bug is only related to software or hardware. – Attilah Aug 09 '12 at 17:08
  • 1
    @Attila: Which one? I don't know how Microsoft classifies things internally though, as I don't work there. – Jon Skeet Aug 09 '12 at 17:13
1

It could be either. Languages and compilers can both have bugs. A language bug is one that will appear no matter the compiler being used, where as a compiler bug will only appear within a specific compiler.

WhoaItsAFactorial
  • 3,538
  • 4
  • 28
  • 45
1

Actually a bug is considered as a difference in spec and actual implementation.

So yes, in that sense both can have a bug.

A programming language IS the specification of the language. What is possible, is that there is an ambiguity or irregulary in the specification of the language and in that sense you can say it has a bug.

However, possibly there is a difference between the specification of C# and the compiler. In that case, the bug is inside the compiler.

Michel Keijzers
  • 15,025
  • 28
  • 93
  • 119