Skip to content

spec: nil, true, false not reserved words #18193

@simen

Description

@simen

What version of Go are you using (go version)?

go1.7.3 darwin/amd64

What operating system and processor architecture are you using (go env)?

$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/simen/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.7.3/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.7.3/libexec/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/_9/2x43ffkj2t13pf5wn5fwnwtc0000gn/T/go-build537154098=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"

What did you do?

https://play.golang.org/p/5dRCQ7TYEB

package main

import "fmt"

func main() {
  nil := "World"
  true := false
  if (true == false) {
    fmt.Printf("Hello, %s!", nil)
  }
}

What did you expect to see?

Expected the code not to compile because it assigns arbitrary values to (what I expected to be) important reserved words.

What did you see instead?

The code works as … unexpected and prints "Hello, World".

I understand these have status as Predeclared identifiers (https://golang.org/ref/spec#Predeclared_identifiers) but question the value of not flagging these as errors immediately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions