Russ Cox | 0b477ef | 2012-02-16 23:48:57 -0500 | [diff] [blame] | 1 | // run |
Russ Cox | 8658b36 | 2011-10-26 15:27:47 -0700 | [diff] [blame] | 2 | |
| 3 | // Copyright 2011 The Go Authors. All rights reserved. |
| 4 | // Use of this source code is governed by a BSD-style |
| 5 | // license that can be found in the LICENSE file. |
| 6 | |
Russ Cox | 8658b36 | 2011-10-26 15:27:47 -0700 | [diff] [blame] | 7 | // Test that dynamic interface checks treat byte=uint8 |
| 8 | // and rune=int or rune=int32. |
| 9 | |
Rob Pike | fc0dc04 | 2012-02-19 13:19:43 +1100 | [diff] [blame] | 10 | package main |
| 11 | |
Russ Cox | 8658b36 | 2011-10-26 15:27:47 -0700 | [diff] [blame] | 12 | func main() { |
| 13 | var x interface{} |
| 14 | |
| 15 | x = byte(1) |
| 16 | switch x.(type) { |
| 17 | case uint8: |
| 18 | // ok |
| 19 | default: |
Alan Donovan | 052c942 | 2013-02-12 13:17:49 -0500 | [diff] [blame] | 20 | panic("byte != uint8") |
Russ Cox | 8658b36 | 2011-10-26 15:27:47 -0700 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | x = uint8(2) |
| 24 | switch x.(type) { |
| 25 | case byte: |
| 26 | // ok |
| 27 | default: |
Alan Donovan | 052c942 | 2013-02-12 13:17:49 -0500 | [diff] [blame] | 28 | panic("uint8 != byte") |
Russ Cox | 8658b36 | 2011-10-26 15:27:47 -0700 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | rune32 := false |
| 32 | x = rune(3) |
| 33 | switch x.(type) { |
| 34 | case int: |
| 35 | // ok |
| 36 | case int32: |
| 37 | // must be new code |
| 38 | rune32 = true |
| 39 | default: |
Alan Donovan | 052c942 | 2013-02-12 13:17:49 -0500 | [diff] [blame] | 40 | panic("rune != int and rune != int32") |
Russ Cox | 8658b36 | 2011-10-26 15:27:47 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | if rune32 { |
| 44 | x = int32(4) |
| 45 | } else { |
| 46 | x = int(5) |
| 47 | } |
| 48 | switch x.(type) { |
| 49 | case rune: |
| 50 | // ok |
| 51 | default: |
Alan Donovan | 052c942 | 2013-02-12 13:17:49 -0500 | [diff] [blame] | 52 | panic("int (or int32) != rune") |
Russ Cox | 8658b36 | 2011-10-26 15:27:47 -0700 | [diff] [blame] | 53 | } |
| 54 | } |