2012-02-17 04:48:57 +00:00
|
|
|
// run
|
2011-10-26 22:27:47 +00:00
|
|
|
|
2016-04-10 21:32:26 +00:00
|
|
|
// Copyright 2011 The Go Authors. All rights reserved.
|
2011-10-26 22:27:47 +00:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// Test that dynamic interface checks treat byte=uint8
|
|
|
|
// and rune=int or rune=int32.
|
|
|
|
|
2012-02-19 02:19:43 +00:00
|
|
|
package main
|
|
|
|
|
2011-10-26 22:27:47 +00:00
|
|
|
func main() {
|
|
|
|
var x interface{}
|
|
|
|
|
|
|
|
x = byte(1)
|
|
|
|
switch x.(type) {
|
|
|
|
case uint8:
|
|
|
|
// ok
|
|
|
|
default:
|
2013-02-12 18:17:49 +00:00
|
|
|
panic("byte != uint8")
|
2011-10-26 22:27:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
x = uint8(2)
|
|
|
|
switch x.(type) {
|
|
|
|
case byte:
|
|
|
|
// ok
|
|
|
|
default:
|
2013-02-12 18:17:49 +00:00
|
|
|
panic("uint8 != byte")
|
2011-10-26 22:27:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rune32 := false
|
|
|
|
x = rune(3)
|
|
|
|
switch x.(type) {
|
|
|
|
case int:
|
|
|
|
// ok
|
|
|
|
case int32:
|
|
|
|
// must be new code
|
|
|
|
rune32 = true
|
|
|
|
default:
|
2013-02-12 18:17:49 +00:00
|
|
|
panic("rune != int and rune != int32")
|
2011-10-26 22:27:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if rune32 {
|
|
|
|
x = int32(4)
|
|
|
|
} else {
|
|
|
|
x = int(5)
|
|
|
|
}
|
|
|
|
switch x.(type) {
|
|
|
|
case rune:
|
|
|
|
// ok
|
|
|
|
default:
|
2013-02-12 18:17:49 +00:00
|
|
|
panic("int (or int32) != rune")
|
2011-10-26 22:27:47 +00:00
|
|
|
}
|
|
|
|
}
|