-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go/ssa/interp: support conversions to slices of named bytes
Support for conversions from string to slices of named byte and rune types and vice versa. Fixes golang/go#55115 Change-Id: Ie0fb94385f1bc89789fe299cc0c39063db676c21 Reviewed-on: https://go-review.googlesource.com/c/tools/+/501301 Reviewed-by: Alan Donovan <[email protected]> Auto-Submit: Tim King <[email protected]> gopls-CI: kokoro <[email protected]> Run-TryBot: Tim King <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
- Loading branch information
1 parent
14ec3c0
commit ad52c1c
Showing
3 changed files
with
41 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2023 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 | ||
|
||
import "reflect" | ||
|
||
func main() { | ||
type MyByte byte | ||
type MyRune rune | ||
type MyString string | ||
|
||
a := []MyByte{'a', 'b', 'c'} | ||
if s := string(a); s != "abc" { | ||
panic(s) | ||
} | ||
|
||
b := []MyRune{'五', '五'} | ||
if s := string(b); s != "五五" { | ||
panic(s) | ||
} | ||
|
||
c := []MyByte{'l', 'o', 'r', 'e', 'm'} | ||
if s := MyString(c); s != MyString("lorem") { | ||
panic(s) | ||
} | ||
|
||
d := "lorem" | ||
if a := []MyByte(d); !reflect.DeepEqual(a, []MyByte{'l', 'o', 'r', 'e', 'm'}) { | ||
panic(a) | ||
} | ||
|
||
e := 42 | ||
if s := MyString(e); s != "*" { | ||
panic(s) | ||
} | ||
} |