aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/types2/testdata/check/builtins.src
blob: 6d1f47129b9c16d2935a66c6eb97a740550041ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
// Copyright 2012 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.

// builtin calls

package builtins

import "unsafe"

func f0() {}

func append1() {
	var b byte
	var x int
	var s []byte
	_ = append() // ERROR not enough arguments
	_ = append("foo" /* ERROR not a slice */ )
	_ = append(nil /* ERROR not a slice */ , s)
	_ = append(x /* ERROR not a slice */ , s)
	_ = append(s)
	_ = append(s, nil...)
	append /* ERROR not used */ (s)

	_ = append(s, b)
	_ = append(s, x /* ERROR cannot use x */ )
	_ = append(s, s /* ERROR cannot use s */ )
	_ = append(s... ) /* ERROR not enough arguments */
	_ = append(s, b, s /* ERROR too many arguments */ ... )
	_ = append(s, 1, 2, 3)
	_ = append(s, 1, 2, 3, x /* ERROR cannot use x */ , 5, 6, 6)
	_ = append(s, 1, 2 /* ERROR too many arguments */ , s... )
	_ = append([]interface{}(nil), 1, 2, "foo", x, 3.1425, false)

	type S []byte
	type T string
	var t T
	_ = append(s, "foo" /* ERROR cannot use .* in argument to append */ )
	_ = append(s, "foo"...)
	_ = append(S(s), "foo" /* ERROR cannot use .* in argument to append */ )
	_ = append(S(s), "foo"...)
	_ = append(s, t /* ERROR cannot use t */ )
	_ = append(s, t...)
	_ = append(s, T("foo")...)
	_ = append(S(s), t /* ERROR cannot use t */ )
	_ = append(S(s), t...)
	_ = append(S(s), T("foo")...)
	_ = append([]string{}, t /* ERROR cannot use t */ , "foo")
	_ = append([]T{}, t, "foo")
}

// from the spec
func append2() {
	s0 := []int{0, 0}
	s1 := append(s0, 2)                // append a single element     s1 == []int{0, 0, 2}
	s2 := append(s1, 3, 5, 7)          // append multiple elements    s2 == []int{0, 0, 2, 3, 5, 7}
	s3 := append(s2, s0...)            // append a slice              s3 == []int{0, 0, 2, 3, 5, 7, 0, 0}
	s4 := append(s3[3:6], s3[2:]...)   // append overlapping slice    s4 == []int{3, 5, 7, 2, 3, 5, 7, 0, 0}

	var t []interface{}
	t = append(t, 42, 3.1415, "foo")   //                             t == []interface{}{42, 3.1415, "foo"}

	var b []byte
	b = append(b, "bar"...)            // append string contents      b == []byte{'b', 'a', 'r' }

	_ = s4
}

func append3() {
	f1 := func() (s []int) { return }
	f2 := func() (s []int, x int) { return }
	f3 := func() (s []int, x, y int) { return }
	f5 := func() (s []interface{}, x int, y float32, z string, b bool) { return }
	ff := func() (int, float32) { return 0, 0 }
	_ = append(f0 /* ERROR used as value */ ())
	_ = append(f1())
	_ = append(f2())
	_ = append(f3())
	_ = append(f5())
	_ = append(ff /* ERROR not a slice */ ()) // TODO(gri) better error message
}

func cap1() {
	var a [10]bool
	var p *[20]int
	var c chan string
	_ = cap() // ERROR not enough arguments
	_ = cap(1, 2) // ERROR too many arguments
	_ = cap(42 /* ERROR invalid */)
	const _3 = cap(a)
	assert(_3 == 10)
	const _4 = cap(p)
	assert(_4 == 20)
	_ = cap(c)
	cap /* ERROR not used */ (c)

	// issue 4744
	type T struct{ a [10]int }
	const _ = cap(((*T)(nil)).a)

	var s [][]byte
	_ = cap(s)
	_ = cap(s... /* ERROR invalid use of \.\.\. */ )
}

func cap2() {
	f1a := func() (a [10]int) { return }
	f1s := func() (s []int) { return }
	f2 := func() (s []int, x int) { return }
	_ = cap(f0 /* ERROR used as value */ ())
	_ = cap(f1a())
	_ = cap(f1s())
	_ = cap(f2()) // ERROR too many arguments
}

// test cases for issue 7387
func cap3() {
	var f = func() int { return 0 }
	var x = f()
	const (
		_ = cap([4]int{})
		_ = cap([4]int{x})
		_ = cap /* ERROR not constant */ ([4]int{f()})
		_ = cap /* ERROR not constant */ ([4]int{cap([]int{})})
		_ = cap([4]int{cap([4]int{})})
	)
	var y float64
	var z complex128
	const (
		_ = cap([4]float64{})
		_ = cap([4]float64{y})
		_ = cap([4]float64{real(2i)})
		_ = cap /* ERROR not constant */ ([4]float64{real(z)})
	)
	var ch chan [10]int
	const (
		_ = cap /* ERROR not constant */ (<-ch)
		_ = cap /* ERROR not constant */ ([4]int{(<-ch)[0]})
	)
}

func close1() {
	var c chan int
	var r <-chan int
	close() // ERROR not enough arguments
	close(1, 2) // ERROR too many arguments
	close(42 /* ERROR not a channel */)
	close(r /* ERROR receive-only channel */)
	close(c)
	_ = close /* ERROR used as value */ (c)

	var s []chan int
	close(s... /* ERROR invalid use of \.\.\. */ )
}

func close2() {
	f1 := func() (ch chan int) { return }
	f2 := func() (ch chan int, x int) { return }
	close(f0 /* ERROR used as value */ ())
	close(f1())
	close(f2()) // ERROR too many arguments
}

func complex1() {
	var i32 int32
	var f32 float32
	var f64 float64
	var c64 complex64
	var c128 complex128
	_ = complex() // ERROR not enough arguments
	_ = complex(1) // ERROR not enough arguments
	_ = complex(true /* ERROR mismatched types */ , 0)
	_ = complex(i32 /* ERROR expected floating-point */ , 0)
	_ = complex("foo" /* ERROR mismatched types */ , 0)
	_ = complex(c64 /* ERROR expected floating-point */ , 0)
	_ = complex(0 /* ERROR mismatched types */ , true)
	_ = complex(0 /* ERROR expected floating-point */ , i32)
	_ = complex(0 /* ERROR mismatched types */ , "foo")
	_ = complex(0 /* ERROR expected floating-point */ , c64)
	_ = complex(f32, f32)
	_ = complex(f32, 1)
	_ = complex(f32, 1.0)
	_ = complex(f32, 'a')
	_ = complex(f64, f64)
	_ = complex(f64, 1)
	_ = complex(f64, 1.0)
	_ = complex(f64, 'a')
	_ = complex(f32 /* ERROR mismatched types */ , f64)
	_ = complex(f64 /* ERROR mismatched types */ , f32)
	_ = complex(1, 1)
	_ = complex(1, 1.1)
	_ = complex(1, 'a')
	complex /* ERROR not used */ (1, 2)

	var _ complex64 = complex(f32, f32)
	var _ complex64 = complex /* ERROR cannot use .* in variable declaration */ (f64, f64)

	var _ complex128 = complex /* ERROR cannot use .* in variable declaration */ (f32, f32)
	var _ complex128 = complex(f64, f64)

	// untyped constants
	const _ int = complex(1, 0)
	const _ float32 = complex(1, 0)
	const _ complex64 = complex(1, 0)
	const _ complex128 = complex(1, 0)
	const _ = complex(0i, 0i)
	const _ = complex(0i, 0)
	const _ int = 1.0 + complex(1, 0i)

	const _ int = complex /* ERROR int */ (1.1, 0)
	const _ float32 = complex /* ERROR float32 */ (1, 2)

	// untyped values
	var s uint
	_ = complex(1 /* ERROR integer */ <<s, 0)
	const _ = complex /* ERROR not constant */ (1 /* ERROR integer */ <<s, 0)
	var _ int = complex /* ERROR cannot use .* in variable declaration */ (1 /* ERROR integer */ <<s, 0)

	// floating-point argument types must be identical
	type F32 float32
	type F64 float64
	var x32 F32
	var x64 F64
	c64 = complex(x32, x32)
	_ = complex(x32 /* ERROR mismatched types */ , f32)
	_ = complex(f32 /* ERROR mismatched types */ , x32)
	c128 = complex(x64, x64)
	_ = c128
	_ = complex(x64 /* ERROR mismatched types */ , f64)
	_ = complex(f64 /* ERROR mismatched types */ , x64)

	var t []float32
	_ = complex(t... /* ERROR invalid use of \.\.\. */ )
}

func complex2() {
	f1 := func() (x float32) { return }
	f2 := func() (x, y float32) { return }
	f3 := func() (x, y, z float32) { return }
	_ = complex(f0 /* ERROR used as value */ ())
	_ = complex(f1()) // ERROR not enough arguments
	_ = complex(f2())
	_ = complex(f3()) // ERROR too many arguments
}

func copy1() {
	copy() // ERROR not enough arguments
	copy("foo") // ERROR not enough arguments
	copy([ /* ERROR copy expects slice arguments */ ...]int{}, []int{})
	copy([ /* ERROR copy expects slice arguments */ ]int{}, [...]int{})
	copy([ /* ERROR different element types */ ]int8{}, "foo")

	// spec examples
	var a = [...]int{0, 1, 2, 3, 4, 5, 6, 7}
	var s = make([]int, 6)
	var b = make([]byte, 5)
	n1 := copy(s, a[0:])            // n1 == 6, s == []int{0, 1, 2, 3, 4, 5}
	n2 := copy(s, s[2:])            // n2 == 4, s == []int{2, 3, 4, 5, 4, 5}
	n3 := copy(b, "Hello, World!")  // n3 == 5, b == []byte("Hello")
	_, _, _ = n1, n2, n3

	var t [][]int
	copy(t, t)
	copy(t /* ERROR copy expects slice arguments */ , nil)
	copy(nil /* ERROR copy expects slice arguments */ , t)
	copy(nil /* ERROR copy expects slice arguments */ , nil)
	copy(t... /* ERROR invalid use of \.\.\. */ )
}

func copy2() {
	f1 := func() (a []int) { return }
	f2 := func() (a, b []int) { return }
	f3 := func() (a, b, c []int) { return }
	copy(f0 /* ERROR used as value */ ())
	copy(f1()) // ERROR not enough arguments
	copy(f2())
	copy(f3()) // ERROR too many arguments
}

func delete1() {
	var m map[string]int
	var s string
	delete() // ERROR not enough arguments
	delete(1) // ERROR not enough arguments
	delete(1, 2, 3) // ERROR too many arguments
	delete(m, 0 /* ERROR cannot use */)
	delete(m, s)
	_ = delete /* ERROR used as value */ (m, s)

	var t []map[string]string
	delete(t... /* ERROR invalid use of \.\.\. */ )
}

func delete2() {
	f1 := func() (m map[string]int) { return }
	f2 := func() (m map[string]int, k string) { return }
	f3 := func() (m map[string]int, k string, x float32) { return }
	delete(f0 /* ERROR used as value */ ())
	delete(f1()) // ERROR not enough arguments
	delete(f2())
	delete(f3()) // ERROR too many arguments
}

func imag1() {
	var f32 float32
	var f64 float64
	var c64 complex64
	var c128 complex128
	_ = imag() // ERROR not enough arguments
	_ = imag(1, 2) // ERROR too many arguments
	_ = imag(10)
	_ = imag(2.7182818)
	_ = imag("foo" /* ERROR expected complex */)
	_ = imag('a')
	const _5 = imag(1 + 2i)
	assert(_5 == 2)
	f32 = _5
	f64 = _5
	const _6 = imag(0i)
	assert(_6 == 0)
	f32 = imag(c64)
	f64 = imag(c128)
	f32 = imag /* ERROR cannot use .* in assignment */ (c128)
	f64 = imag /* ERROR cannot use .* in assignment */ (c64)
	imag /* ERROR not used */ (c64)
	_, _ = f32, f64

	// complex type may not be predeclared
	type C64 complex64
	type C128 complex128
	var x64 C64
	var x128 C128
	f32 = imag(x64)
	f64 = imag(x128)

	var a []complex64
	_ = imag(a... /* ERROR invalid use of \.\.\. */ )

	// if argument is untyped, result is untyped
	const _ byte = imag(1.2 + 3i)
	const _ complex128 = imag(1.2 + 3i)

	// lhs constant shift operands are typed as complex128
	var s uint
	_ = imag(1 /* ERROR must be integer */ << s)
}

func imag2() {
	f1 := func() (x complex128) { return }
	f2 := func() (x, y complex128) { return }
	_ = imag(f0 /* ERROR used as value */ ())
	_ = imag(f1())
	_ = imag(f2()) // ERROR too many arguments
}

func len1() {
	const c = "foobar"
	var a [10]bool
	var p *[20]int
	var m map[string]complex128
	_ = len() // ERROR not enough arguments
	_ = len(1, 2) // ERROR too many arguments
	_ = len(42 /* ERROR invalid */)
	const _3 = len(c)
	assert(_3 == 6)
	const _4 = len(a)
	assert(_4 == 10)
	const _5 = len(p)
	assert(_5 == 20)
	_ = len(m)
	len /* ERROR not used */ (c)

	// esoteric case
	var t string
	var hash map[interface{}][]*[10]int
	const n = len /* ERROR not constant */ (hash[recover()][len(t)])
	assert(n == 10) // ok because n has unknown value and no error is reported
	var ch <-chan int
	const nn = len /* ERROR not constant */ (hash[<-ch][len(t)])

	// issue 4744
	type T struct{ a [10]int }
	const _ = len(((*T)(nil)).a)

	var s [][]byte
	_ = len(s)
	_ = len(s... /* ERROR invalid use of \.\.\. */ )
}

func len2() {
	f1 := func() (x []int) { return }
	f2 := func() (x, y []int) { return }
	_ = len(f0 /* ERROR used as value */ ())
	_ = len(f1())
	_ = len(f2()) // ERROR too many arguments
}

// test cases for issue 7387
func len3() {
	var f = func() int { return 0 }
	var x = f()
	const (
		_ = len([4]int{})
		_ = len([4]int{x})
		_ = len /* ERROR not constant */ ([4]int{f()})
		_ = len /* ERROR not constant */ ([4]int{len([]int{})})
		_ = len([4]int{len([4]int{})})
	)
	var y float64
	var z complex128
	const (
		_ = len([4]float64{})
		_ = len([4]float64{y})
		_ = len([4]float64{real(2i)})
		_ = len /* ERROR not constant */ ([4]float64{real(z)})
	)
	var ch chan [10]int
	const (
		_ = len /* ERROR not constant */ (<-ch)
		_ = len /* ERROR not constant */ ([4]int{(<-ch)[0]})
	)
}

func make1() {
	var n int
	var m float32
	var s uint

	_ = make() // ERROR not enough arguments
	_ = make(1 /* ERROR not a type */)
	_ = make(int /* ERROR cannot make */)

	// slices
	_ = make/* ERROR arguments */ ([]int)
	_ = make/* ERROR arguments */ ([]int, 2, 3, 4)
	_ = make([]int, int /* ERROR not an expression */)
	_ = make([]int, 10, float32 /* ERROR not an expression */)
	_ = make([]int, "foo" /* ERROR cannot convert */)
	_ = make([]int, 10, 2.3 /* ERROR truncated */)
	_ = make([]int, 5, 10.0)
	_ = make([]int, 0i)
	_ = make([]int, 1.0)
	_ = make([]int, 1.0<<s)
	_ = make([]int, 1.1 /* ERROR int */ <<s)
	_ = make([]int, - /* ERROR must not be negative */ 1, 10)
	_ = make([]int, 0, - /* ERROR must not be negative */ 1)
	_ = make([]int, - /* ERROR must not be negative */ 1, - /* ERROR must not be negative */ 1)
	_ = make([]int, 1 /* ERROR overflows */ <<100, 1 /* ERROR overflows */ <<100)
	_ = make([]int, 10 /* ERROR length and capacity swapped */ , 9)
	_ = make([]int, 1 /* ERROR overflows */ <<100, 12345)
	_ = make([]int, m /* ERROR must be integer */ )
        _ = &make /* ERROR cannot take address */ ([]int, 0)

	// maps
	_ = make /* ERROR arguments */ (map[int]string, 10, 20)
	_ = make(map[int]float32, int /* ERROR not an expression */)
	_ = make(map[int]float32, "foo" /* ERROR cannot convert */)
	_ = make(map[int]float32, 10)
	_ = make(map[int]float32, n)
	_ = make(map[int]float32, int64(n))
	_ = make(map[string]bool, 10.0)
	_ = make(map[string]bool, 10.0<<s)
        _ = &make /* ERROR cannot take address */ (map[string]bool)

	// channels
	_ = make /* ERROR arguments */ (chan int, 10, 20)
	_ = make(chan int, int /* ERROR not an expression */)
	_ = make(chan<- int, "foo" /* ERROR cannot convert */)
	_ = make(chan int, - /* ERROR must not be negative */ 10)
	_ = make(<-chan float64, 10)
	_ = make(chan chan int, n)
	_ = make(chan string, int64(n))
	_ = make(chan bool, 10.0)
	_ = make(chan bool, 10.0<<s)
        _ = &make /* ERROR cannot take address */ (chan bool)

	make /* ERROR not used */ ([]int, 10)

	var t []int
	_ = make([]int, t[0], t[1])
	_ = make([]int, t... /* ERROR invalid use of \.\.\. */ )
}

func make2() {
	f1 := func() (x []int) { return }
	_ = make(f0 /* ERROR not a type */ ())
	_ = make(f1 /* ERROR not a type */ ())
}

func new1() {
	_ = new() // ERROR not enough arguments
	_ = new(1, 2) // ERROR too many arguments
	_ = new("foo" /* ERROR not a type */)
	p := new(float64)
	_ = new(struct{ x, y int })
	q := new(*float64)
	_ = *p == **q
	new /* ERROR not used */ (int)
        _ = &new /* ERROR cannot take address */ (int)

	_ = new(int... /* ERROR invalid use of \.\.\. */ )
}

func new2() {
	f1 := func() (x []int) { return }
	_ = new(f0 /* ERROR not a type */ ())
	_ = new(f1 /* ERROR not a type */ ())
}

func panic1() {
	panic() // ERROR not enough arguments
	panic(1, 2) // ERROR too many arguments
	panic(0)
	panic("foo")
	panic(false)
	panic(1<<10)
	panic(1 << /* ERROR constant shift overflow */ 1000)
	_ = panic /* ERROR used as value */ (0)

	var s []byte
	panic(s)
	panic(s... /* ERROR invalid use of \.\.\. */ )
}

func panic2() {
	f1 := func() (x int) { return }
	f2 := func() (x, y int) { return }
	panic(f0 /* ERROR used as value */ ())
	panic(f1())
	panic(f2()) // ERROR too many arguments
}

func print1() {
	print()
	print(1)
	print(1, 2)
	print("foo")
	print(2.718281828)
	print(false)
	print(1<<10)
	print(1 << /* ERROR constant shift overflow */ 1000)
	println(nil /* ERROR untyped nil */ )

	var s []int
	print(s... /* ERROR invalid use of \.\.\. */ )
	_ = print /* ERROR used as value */ ()
}

func print2() {
	f1 := func() (x int) { return }
	f2 := func() (x, y int) { return }
	f3 := func() (x int, y float32, z string) { return }
	print(f0 /* ERROR used as value */ ())
	print(f1())
	print(f2())
	print(f3())
}

func println1() {
	println()
	println(1)
	println(1, 2)
	println("foo")
	println(2.718281828)
	println(false)
	println(1<<10)
	println(1 << /* ERROR constant shift overflow */ 1000)
	println(nil /* ERROR untyped nil */ )

	var s []int
	println(s... /* ERROR invalid use of \.\.\. */ )
	_ = println /* ERROR used as value */ ()
}

func println2() {
	f1 := func() (x int) { return }
	f2 := func() (x, y int) { return }
	f3 := func() (x int, y float32, z string) { return }
	println(f0 /* ERROR used as value */ ())
	println(f1())
	println(f2())
	println(f3())
}

func real1() {
	var f32 float32
	var f64 float64
	var c64 complex64
	var c128 complex128
	_ = real() // ERROR not enough arguments
	_ = real(1, 2) // ERROR too many arguments
	_ = real(10)
	_ = real(2.7182818)
	_ = real("foo" /* ERROR expected complex */)
	const _5 = real(1 + 2i)
	assert(_5 == 1)
	f32 = _5
	f64 = _5
	const _6 = real(0i)
	assert(_6 == 0)
	f32 = real(c64)
	f64 = real(c128)
	f32 = real /* ERROR cannot use .* in assignment */ (c128)
	f64 = real /* ERROR cannot use .* in assignment */ (c64)
	real /* ERROR not used */ (c64)

	// complex type may not be predeclared
	type C64 complex64
	type C128 complex128
	var x64 C64
	var x128 C128
	f32 = imag(x64)
	f64 = imag(x128)
	_, _ = f32, f64

	var a []complex64
	_ = real(a... /* ERROR invalid use of \.\.\. */ )

	// if argument is untyped, result is untyped
	const _ byte = real(1 + 2.3i)
	const _ complex128 = real(1 + 2.3i)

	// lhs constant shift operands are typed as complex128
	var s uint
	_ = real(1 /* ERROR must be integer */ << s)
}

func real2() {
	f1 := func() (x complex128) { return }
	f2 := func() (x, y complex128) { return }
	_ = real(f0 /* ERROR used as value */ ())
	_ = real(f1())
	_ = real(f2()) // ERROR too many arguments
}

func recover1() {
	_ = recover()
	_ = recover(10) // ERROR too many arguments
	recover()

	var s []int
	recover(s... /* ERROR invalid use of \.\.\. */ )
}

func recover2() {
	f1 := func() (x int) { return }
	f2 := func() (x, y int) { return }
	_ = recover(f0 /* ERROR used as value */ ())
	_ = recover(f1()) // ERROR too many arguments
	_ = recover(f2()) // ERROR too many arguments
}

// assuming types.DefaultPtrSize == 8
type S0 struct{      // offset
	a bool       //  0
	b rune       //  4
	c *int       //  8
	d bool       // 16
	e complex128 // 24
}                    // 40

type S1 struct{   // offset
	x float32 //  0
	y string  //  8
	z *S1     // 24
	S0        // 32
}                 // 72

type S2 struct{ // offset
	*S1     //  0
}               //  8

type S3 struct { // offset
	a int64  //  0
	b int32  //  8
}                // 12

type S4 struct { // offset
	S3       //  0
	int32    // 12
}                // 16

type S5 struct {   // offset
	a [3]int32 //  0
	b int32    // 12
}                  // 16

func (S2) m() {}

func Alignof1() {
	var x int
	_ = unsafe.Alignof() // ERROR not enough arguments
	_ = unsafe.Alignof(1, 2) // ERROR too many arguments
	_ = unsafe.Alignof(int /* ERROR not an expression */)
	_ = unsafe.Alignof(42)
	_ = unsafe.Alignof(new(struct{}))
	_ = unsafe.Alignof(1<<10)
	_ = unsafe.Alignof(1 << /* ERROR constant shift overflow */ 1000)
	_ = unsafe.Alignof(nil /* ERROR "untyped nil */ )
	unsafe /* ERROR not used */ .Alignof(x)

	var y S0
	assert(unsafe.Alignof(y.a) == 1)
	assert(unsafe.Alignof(y.b) == 4)
	assert(unsafe.Alignof(y.c) == 8)
	assert(unsafe.Alignof(y.d) == 1)
	assert(unsafe.Alignof(y.e) == 8)

	var s []byte
	_ = unsafe.Alignof(s)
	_ = unsafe.Alignof(s... /* ERROR invalid use of \.\.\. */ )
}

func Alignof2() {
	f1 := func() (x int32) { return }
	f2 := func() (x, y int32) { return }
	_ = unsafe.Alignof(f0 /* ERROR used as value */ ())
	assert(unsafe.Alignof(f1()) == 4)
	_ = unsafe.Alignof(f2()) // ERROR too many arguments
}

func Offsetof1() {
	var x struct{ f int }
	_ = unsafe.Offsetof() // ERROR not enough arguments
	_ = unsafe.Offsetof(1, 2) // ERROR too many arguments
	_ = unsafe.Offsetof(int /* ERROR not a selector expression */ )
	_ = unsafe.Offsetof(x /* ERROR not a selector expression */ )
	_ = unsafe.Offsetof(nil /* ERROR not a selector expression */ )
	_ = unsafe.Offsetof(x.f)
	_ = unsafe.Offsetof((x.f))
	_ = unsafe.Offsetof((((((((x))).f)))))
	unsafe /* ERROR not used */ .Offsetof(x.f)

	var y0 S0
	assert(unsafe.Offsetof(y0.a) == 0)
	assert(unsafe.Offsetof(y0.b) == 4)
	assert(unsafe.Offsetof(y0.c) == 8)
	assert(unsafe.Offsetof(y0.d) == 16)
	assert(unsafe.Offsetof(y0.e) == 24)

	var y1 S1
	assert(unsafe.Offsetof(y1.x) == 0)
	assert(unsafe.Offsetof(y1.y) == 8)
	assert(unsafe.Offsetof(y1.z) == 24)
	assert(unsafe.Offsetof(y1.S0) == 32)

	assert(unsafe.Offsetof(y1.S0.a) == 0) // relative to S0
	assert(unsafe.Offsetof(y1.a) == 32)   // relative to S1
	assert(unsafe.Offsetof(y1.b) == 36)   // relative to S1
	assert(unsafe.Offsetof(y1.c) == 40)   // relative to S1
	assert(unsafe.Offsetof(y1.d) == 48)   // relative to S1
	assert(unsafe.Offsetof(y1.e) == 56)   // relative to S1

	var y1p *S1
	assert(unsafe.Offsetof(y1p.S0) == 32)

	type P *S1
	var p P = y1p
	assert(unsafe.Offsetof(p.S0) == 32)

	var y2 S2
	assert(unsafe.Offsetof(y2.S1) == 0)
	_ = unsafe.Offsetof(y2 /* ERROR embedded via a pointer */ .x)
	_ = unsafe.Offsetof(y2 /* ERROR method value */ .m)

	var s []byte
	_ = unsafe.Offsetof(s... /* ERROR invalid use of \.\.\. */ )
}

func Offsetof2() {
	f1 := func() (x int32) { return }
	f2 := func() (x, y int32) { return }
	_ = unsafe.Offsetof(f0 /* ERROR not a selector expression */ ())
	_ = unsafe.Offsetof(f1 /* ERROR not a selector expression */ ())
	_ = unsafe.Offsetof(f2 /* ERROR not a selector expression */ ())
}

func Sizeof1() {
	var x int
	_ = unsafe.Sizeof() // ERROR not enough arguments
	_ = unsafe.Sizeof(1, 2) // ERROR too many arguments
	_ = unsafe.Sizeof(int /* ERROR not an expression */)
	_ = unsafe.Sizeof(42)
	_ = unsafe.Sizeof(new(complex128))
	_ = unsafe.Sizeof(1<<10)
	_ = unsafe.Sizeof(1 << /* ERROR constant shift overflow */ 1000)
	_ = unsafe.Sizeof(nil /* ERROR untyped nil */ )
	unsafe /* ERROR not used */ .Sizeof(x)

	// basic types have size guarantees
	assert(unsafe.Sizeof(byte(0)) == 1)
	assert(unsafe.Sizeof(uint8(0)) == 1)
	assert(unsafe.Sizeof(int8(0)) == 1)
	assert(unsafe.Sizeof(uint16(0)) == 2)
	assert(unsafe.Sizeof(int16(0)) == 2)
	assert(unsafe.Sizeof(uint32(0)) == 4)
	assert(unsafe.Sizeof(int32(0)) == 4)
	assert(unsafe.Sizeof(float32(0)) == 4)
	assert(unsafe.Sizeof(uint64(0)) == 8)
	assert(unsafe.Sizeof(int64(0)) == 8)
	assert(unsafe.Sizeof(float64(0)) == 8)
	assert(unsafe.Sizeof(complex64(0)) == 8)
	assert(unsafe.Sizeof(complex128(0)) == 16)

	var y0 S0
	assert(unsafe.Sizeof(y0.a) == 1)
	assert(unsafe.Sizeof(y0.b) == 4)
	assert(unsafe.Sizeof(y0.c) == 8)
	assert(unsafe.Sizeof(y0.d) == 1)
	assert(unsafe.Sizeof(y0.e) == 16)
	assert(unsafe.Sizeof(y0) == 40)

	var y1 S1
	assert(unsafe.Sizeof(y1) == 72)

	var y2 S2
	assert(unsafe.Sizeof(y2) == 8)

	var y3 S3
	assert(unsafe.Sizeof(y3) == 12)

	var y4 S4
	assert(unsafe.Sizeof(y4) == 16)

	var y5 S5
	assert(unsafe.Sizeof(y5) == 16)

	var a3 [10]S3
	assert(unsafe.Sizeof(a3) == 156)

	// test case for issue 5670
	type T struct {
		a int32
		_ int32
		c int32
	}
	assert(unsafe.Sizeof(T{}) == 12)

	var s []byte
	_ = unsafe.Sizeof(s)
	_ = unsafe.Sizeof(s... /* ERROR invalid use of \.\.\. */ )
}

func Sizeof2() {
	f1 := func() (x int64) { return }
	f2 := func() (x, y int64) { return }
	_ = unsafe.Sizeof(f0 /* ERROR used as value */ ())
	assert(unsafe.Sizeof(f1()) == 8)
	_ = unsafe.Sizeof(f2()) // ERROR too many arguments
}

// self-testing only
func assert1() {
	var x int
	assert() /* ERROR not enough arguments */
	assert(1, 2) /* ERROR too many arguments */
	assert("foo" /* ERROR boolean constant */ )
	assert(x /* ERROR boolean constant */)
	assert(true)
	assert /* ERROR failed */ (false)
	_ = assert(true)

	var s []byte
	assert(s... /* ERROR invalid use of \.\.\. */ )
}

func assert2() {
	f1 := func() (x bool) { return }
	f2 := func() (x bool) { return }
	assert(f0 /* ERROR used as value */ ())
	assert(f1 /* ERROR boolean constant */ ())
	assert(f2 /* ERROR boolean constant */ ())
}

// self-testing only
func trace1() {
	// Uncomment the code below to test trace - will produce console output
	// _ = trace /* ERROR no value */ ()
	// _ = trace(1)
	// _ = trace(true, 1.2, '\'', "foo", 42i, "foo" <= "bar")

	var s []byte
	trace(s... /* ERROR invalid use of \.\.\. */ )
}

func trace2() {
	f1 := func() (x int) { return }
	f2 := func() (x int, y string) { return }
	f3 := func() (x int, y string, z []int) { return }
	_ = f1
	_ = f2
	_ = f3
	// Uncomment the code below to test trace - will produce console output
	// trace(f0())
	// trace(f1())
	// trace(f2())
	// trace(f3())
	// trace(f0(), 1)
	// trace(f1(), 1, 2)
	// trace(f2(), 1, 2, 3)
	// trace(f3(), 1, 2, 3, 4)
}