Files
llgo/cl/_testdata/debug/in.go

173 lines
2.8 KiB
Go
Raw Normal View History

2024-09-15 20:21:16 +08:00
package main
2024-09-14 18:46:44 +08:00
2024-09-15 12:05:27 +08:00
import "errors"
type Base struct {
name string
2024-09-14 18:46:44 +08:00
}
2024-09-15 12:05:27 +08:00
type E struct {
2024-09-15 20:21:16 +08:00
// Base
2024-09-15 12:05:27 +08:00
i int
}
type StructWithAllTypeFields struct {
2024-09-18 18:10:45 +08:00
i8 int8
i16 int16
i32 int32
i64 int64
i int
u8 uint8
u16 uint16
u32 uint32
u64 uint64
u uint
f32 float32
f64 float64
b bool
c64 complex64
c128 complex128
slice []int
arr [3]int
arr2 [3]E
s string
e E
pf *StructWithAllTypeFields // resursive
pi *int
2024-09-18 18:26:36 +08:00
intr Interface
2024-09-18 19:45:11 +08:00
m map[string]uint64
2024-09-18 19:52:01 +08:00
c chan int
err error
2024-09-18 20:31:45 +08:00
fn func(string) (int, error)
pad1 int
pad2 int
2024-09-14 18:46:44 +08:00
}
2024-09-15 12:05:27 +08:00
type Interface interface {
Foo(a []int, b string) int
2024-09-14 18:46:44 +08:00
}
2024-09-15 12:05:27 +08:00
type Struct struct{}
func (s *Struct) Foo(a []int, b string) int {
2024-09-14 18:46:44 +08:00
return 1
}
2024-09-15 12:05:27 +08:00
func FuncWithAllTypeStructParam(s StructWithAllTypeFields) {
println(&s)
println(len(s.s))
2024-09-14 18:46:44 +08:00
}
2024-09-15 12:05:27 +08:00
// Params is a function with all types of parameters.
func FuncWithAllTypeParams(
i8 int8,
i16 int16,
i32 int32,
i64 int64,
i int,
u8 uint8,
u16 uint16,
u32 uint32,
u64 uint64,
u uint,
f32 float32,
f64 float64,
b bool,
2024-09-15 20:54:10 +08:00
c64 complex64,
c128 complex128,
2024-09-18 18:10:45 +08:00
slice []int,
arr [3]int,
arr2 [3]E,
s string,
2024-09-15 12:05:27 +08:00
e E,
f StructWithAllTypeFields,
pf *StructWithAllTypeFields,
pi *int,
2024-09-18 18:26:36 +08:00
intr Interface,
2024-09-18 19:45:11 +08:00
m map[string]uint64,
2024-09-18 19:52:01 +08:00
c chan int,
2024-09-18 18:26:36 +08:00
err error,
2024-09-18 20:31:45 +08:00
fn func(string) (int, error),
2024-09-15 12:05:27 +08:00
) (int, error) {
println(
2024-09-15 20:21:16 +08:00
i8, i16, i32, i64, i, u8, u16, u32, u64, u,
f32, f64, b,
2024-09-15 20:54:10 +08:00
c64, c128,
2024-09-18 18:10:45 +08:00
slice, arr[0:],
s,
2024-09-18 18:26:36 +08:00
&e,
2024-09-18 19:45:11 +08:00
&f, pf, pi, intr, m,
2024-09-18 19:52:01 +08:00
c,
2024-09-18 18:26:36 +08:00
err,
2024-09-18 20:31:45 +08:00
fn,
2024-09-15 12:05:27 +08:00
)
return 1, errors.New("Some error")
2024-09-14 18:46:44 +08:00
}
2024-09-15 20:21:16 +08:00
func main() {
i := 100
s := StructWithAllTypeFields{
2024-09-18 18:10:45 +08:00
i8: 1,
i16: 2,
i32: 3,
i64: 4,
i: 5,
u8: 6,
u16: 7,
u32: 8,
u64: 9,
u: 10,
f32: 11,
f64: 12,
b: true,
c64: 13 + 14i,
c128: 15 + 16i,
slice: []int{21, 22, 23},
arr: [3]int{24, 25, 26},
arr2: [3]E{{i: 27}, {i: 28}, {i: 29}},
s: "hello",
e: E{i: 30},
pf: &StructWithAllTypeFields{},
pi: &i,
2024-09-18 18:26:36 +08:00
intr: &Struct{},
2024-09-18 19:45:11 +08:00
m: map[string]uint64{"a": 31, "b": 32},
2024-09-18 19:52:01 +08:00
c: make(chan int),
err: errors.New("Test error"),
2024-09-18 20:31:45 +08:00
fn: func(s string) (int, error) {
println("fn:", s)
i = 201
return 1, errors.New("fn error")
},
pad1: 100,
pad2: 200,
2024-09-15 20:21:16 +08:00
}
2024-09-18 22:05:41 +08:00
globalStructPtr = &s
globalStruct = s
println("globalInt:", globalInt)
2024-09-15 20:21:16 +08:00
println("s:", &s)
FuncWithAllTypeStructParam(s)
println("called function with struct")
i, err := FuncWithAllTypeParams(
s.i8, s.i16, s.i32, s.i64, s.i, s.u8, s.u16, s.u32, s.u64, s.u,
s.f32, s.f64, s.b,
2024-09-15 20:54:10 +08:00
s.c64, s.c128,
2024-09-18 18:10:45 +08:00
s.slice, s.arr, s.arr2,
s.s,
2024-09-15 20:21:16 +08:00
s.e, s,
s.pf, s.pi,
2024-09-18 18:26:36 +08:00
s.intr,
2024-09-18 19:45:11 +08:00
s.m,
2024-09-18 19:52:01 +08:00
s.c,
2024-09-18 18:26:36 +08:00
s.err,
2024-09-18 20:31:45 +08:00
s.fn,
2024-09-15 20:21:16 +08:00
)
println(i, err)
println("called function with types")
2024-09-18 22:05:41 +08:00
println(globalStructPtr)
println(&globalStruct)
2024-09-15 20:21:16 +08:00
println("done")
}
2024-09-18 22:05:41 +08:00
var globalInt int = 301
var globalStruct StructWithAllTypeFields
var globalStructPtr *StructWithAllTypeFields