diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-01-25 20:56:26 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-01-25 20:56:26 +0000 |
commit | df1304ee03f41aed179545d1e8b4684cfd22bbdf (patch) | |
tree | c68d6b2a9f5b82a23171b0a488a4b7e5c63ad860 /libgo/go/go/printer | |
parent | 3be18e47c33b61365786831e0f967f42b09922c9 (diff) |
libgo: Update to weekly.2012-01-15.
From-SVN: r183539
Diffstat (limited to 'libgo/go/go/printer')
-rw-r--r-- | libgo/go/go/printer/printer.go | 7 | ||||
-rw-r--r-- | libgo/go/go/printer/printer_test.go | 15 |
2 files changed, 21 insertions, 1 deletions
diff --git a/libgo/go/go/printer/printer.go b/libgo/go/go/printer/printer.go index a78cfc65fcc..c720f2e665c 100644 --- a/libgo/go/go/printer/printer.go +++ b/libgo/go/go/printer/printer.go @@ -773,8 +773,13 @@ func (p *printer) print(args ...interface{}) { next = p.fset.Position(x) // accurate position of next item } tok = p.lastTok + case string: + // incorrect AST - print error message + data = x + isLit = true + tok = token.STRING default: - fmt.Fprintf(os.Stderr, "print: unsupported argument type %T\n", f) + fmt.Fprintf(os.Stderr, "print: unsupported argument %v (%T)\n", f, f) panic("go/printer type") } p.lastTok = tok diff --git a/libgo/go/go/printer/printer_test.go b/libgo/go/go/printer/printer_test.go index 45477d40f6e..525fcc1595f 100644 --- a/libgo/go/go/printer/printer_test.go +++ b/libgo/go/go/printer/printer_test.go @@ -204,3 +204,18 @@ func init() { panic("got " + s + ", want " + name) } } + +// Verify that the printer doesn't crash if the AST contains BadXXX nodes. +func TestBadNodes(t *testing.T) { + const src = "package p\n(" + const res = "package p\nBadDecl\n" + f, err := parser.ParseFile(fset, "", src, parser.ParseComments) + if err == nil { + t.Errorf("expected illegal program") + } + var buf bytes.Buffer + Fprint(&buf, fset, f) + if buf.String() != res { + t.Errorf("got %q, expected %q", buf.String(), res) + } +} |