Skip to content

Commit

Permalink
cmd/compile: reject identifiers beginning with non-ASCII digit
Browse files Browse the repository at this point in the history
Fixes #11359.

Change-Id: I0fdfa410939f7e42020cbb19d74a67e1cc3cd610
Reviewed-on: https://go-review.googlesource.com/16919
Reviewed-by: Ian Lance Taylor <iant@golang.org>
  • Loading branch information
rsc committed Nov 16, 2015
1 parent f2eb3de commit 247959d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/cmd/compile/internal/gc/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,9 @@ talph:
if !unicode.IsLetter(r) && !unicode.IsDigit(r) && (importpkg == nil || r != 0xb7) {
Yyerror("invalid identifier character U+%04x", r)
}
if cp.Len() == 0 && unicode.IsDigit(r) {
Yyerror("identifier cannot begin with digit U+%04x", r)
}
cp.WriteRune(r)
} else if !isAlnum(c) && c != '_' {
break
Expand Down
11 changes: 11 additions & 0 deletions test/fixedbugs/issue11359.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// errorcheck

// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// identifiers beginning with non-ASCII digits were incorrectly accepted.
// issue 11359.

package p
var ۶ = 0 // ERROR "identifier cannot begin with digit"

0 comments on commit 247959d

Please sign in to comment.