mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-06 03:53:42 +00:00
reflect: add support for named types
With this change, it becomes possible to get the element type of named slices, pointers, and channels. This is a prerequisite to enable the common named struct types. There's more to come.
This commit is contained in:
committed by
Ron Evans
parent
33dc4b5121
commit
95721a8d8c
Vendored
+5
@@ -9,6 +9,8 @@ type (
|
||||
myint int
|
||||
myslice []byte
|
||||
myslice2 []myint
|
||||
mychan chan int
|
||||
myptr *int
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -55,10 +57,12 @@ func main() {
|
||||
unsafe.Pointer(new(int)),
|
||||
// channels
|
||||
zeroChan,
|
||||
mychan(zeroChan),
|
||||
// pointers
|
||||
new(int),
|
||||
new(error),
|
||||
&n,
|
||||
myptr(new(int)),
|
||||
// slices
|
||||
[]byte{1, 2, 3},
|
||||
make([]uint8, 2, 5),
|
||||
@@ -70,6 +74,7 @@ func main() {
|
||||
[]float64{1, 1.64},
|
||||
[]complex64{1, 1.64 + 0.3i},
|
||||
[]complex128{1, 1.128 + 0.4i},
|
||||
myslice{5, 3, 11},
|
||||
// array
|
||||
[4]int{1, 2, 3, 4},
|
||||
// functions
|
||||
|
||||
Vendored
+21
@@ -66,6 +66,9 @@ reflect type: unsafe.Pointer
|
||||
reflect type: chan
|
||||
chan: int
|
||||
nil: true
|
||||
reflect type: chan
|
||||
chan: int
|
||||
nil: true
|
||||
reflect type: ptr
|
||||
pointer: true int
|
||||
nil: false
|
||||
@@ -82,6 +85,11 @@ reflect type: ptr
|
||||
nil: false
|
||||
reflect type: int settable=true
|
||||
int: 42
|
||||
reflect type: ptr
|
||||
pointer: true int
|
||||
nil: false
|
||||
reflect type: int settable=true
|
||||
int: 0
|
||||
reflect type: slice
|
||||
slice: uint8 3 3
|
||||
pointer: true
|
||||
@@ -181,6 +189,19 @@ reflect type: slice
|
||||
indexing: 1
|
||||
reflect type: complex128 settable=true
|
||||
complex: (+1.128000e+000+4.000000e-001i)
|
||||
reflect type: slice
|
||||
slice: uint8 3 3
|
||||
pointer: true
|
||||
nil: false
|
||||
indexing: 0
|
||||
reflect type: uint8 settable=true
|
||||
uint: 5
|
||||
indexing: 1
|
||||
reflect type: uint8 settable=true
|
||||
uint: 3
|
||||
indexing: 2
|
||||
reflect type: uint8 settable=true
|
||||
uint: 11
|
||||
reflect type: array
|
||||
array
|
||||
reflect type: func
|
||||
|
||||
Reference in New Issue
Block a user