One year of Go

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Fri Nov 12 10:50:20 PST 2010


On 11/12/10 10:33 AM, bearophile wrote:
> Steven Schveighoffer:
>
>> If that is invalid code, then I stand corrected.  If it compiles, then
>> it's a serious flaw that is inexcusable.
>
> You need more time to try it on the site that Walter thinks is useless:
> http://ideone.com/Ju80U
>
> This Go code:
>
> package main
>
> import "fmt"
>
> func main() {
>    x := 5
>    if(x == 6)
>    {
>      x++;
>    }
>    fmt.Printf("%d\n", x)
> }
>
>
> Produces this compilation error (gc-2010-07-14):
> prog.go:7: x == 6 not used
>
> The interactive compiler on the Go site produces the same outcome:
> http://golang.org/
>
> Bye,
> bearophile

Try this then:

package main

import "fmt"

func blah() bool {
    return false
}

func main() {
   x := 5
   if(blah())
   {
     x++;
   }
   fmt.Printf("%d\n", x)
}

which evaluates x++ and prints 6 regardless of blah's result.

Ouch.

So Sean was right - it _did_ take him five minutes to find a fatal flaw.


Andrei


More information about the Digitalmars-d mailing list