1
0
mirror of https://github.com/golang/go synced 2024-11-15 01:20:28 -07:00
go/test/fixedbugs/issue15039.go
Matthew Dempsky e6066711a0 cmd/compile, runtime: fix pedantic int->string conversions
Previously, cmd/compile rejected constant int->string conversions if
the integer value did not fit into an "int" value. Also, runtime
incorrectly truncated 64-bit values to 32-bit before checking if
they're a valid Unicode code point. According to the Go spec, both of
these cases should instead yield "\uFFFD".

Fixes #15039.

Change-Id: I3c8a3ad9a0780c0a8dc1911386a523800fec9764
Reviewed-on: https://go-review.googlesource.com/21344
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-03-31 10:28:23 +00:00

26 lines
545 B
Go

// run
// Copyright 2016 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.
package main
func main() {
const fffd = "\uFFFD"
// runtime.intstring used to convert int64 to rune without checking
// for truncation.
u := uint64(0x10001f4a9)
big := string(u)
if big != fffd {
panic("big != bad")
}
// cmd/compile used to require integer constants to fit into an "int".
const huge = string(1<<100)
if huge != fffd {
panic("huge != bad")
}
}