...

Text file src/go/printer/testdata/generics.input

Documentation: go/printer/testdata

     1// Copyright 2020 The Go Authors. All rights reserved.
     2// Use of this source code is governed by a BSD-style
     3// license that can be found in the LICENSE file.
     4
     5package generics
     6
     7func _[A, B any](a A, b B) int {}
     8func _[T any](x, y T) T
     9
    10type T[P any] struct{}
    11type T[P1, P2, P3 any] struct{}
    12
    13type T[P C] struct{}
    14type T[P1, P2, P3 C] struct{}
    15
    16type T[P C[P]] struct{}
    17type T[P1, P2, P3 C[P1, P2, P3]] struct{}
    18
    19func f[P any](x P)
    20func f[P1, P2, P3 any](x1 P1, x2 P2, x3 P3) struct{}
    21
    22func f[P interface{}](x P)
    23func f[P1, P2, P3 interface{ m1(P1); ~P2|~P3 }](x1 P1, x2 P2, x3 P3) struct{}
    24func f[P any](T1[P], T2[P]) T3[P]
    25
    26func (x T[P]) m()
    27func ((T[P])) m(x T[P]) P
    28
    29func _() {
    30	type _ []T[P]
    31	var _ []T[P]
    32	_ = []T[P]{}
    33}
    34
    35// type constraint literals with elided interfaces
    36func _[P ~int, Q int | string]() {}
    37func _[P struct{f int}, Q *P]() {}
    38
    39// various potentially ambiguous type parameter lists (issue #49482)
    40type _[P *T,] struct{}
    41type _[P T | T] struct{}
    42type _[P T | T | T | T] struct{}
    43type _[P *T, _ any] struct{}
    44type _[P (*T),] struct{}
    45type _[P (*T), _ any] struct{}
    46type _[P (T),] struct{}
    47type _[P (T), _ any] struct{}
    48
    49type _[P *struct{}] struct{}
    50type _[P (*struct{})] struct{}
    51type _[P ([]int)] struct{}
    52
    53// a type literal in an |-expression indicates a type parameter list (blank after type parameter list and type)
    54type _[P *[]int] struct{}
    55type _[P *T | T, Q T] struct{}
    56type _[P *[]T | T] struct{}
    57type _[P *T | T | T | T | ~T] struct{}
    58type _[P *T | T | T | ~T | T] struct{}
    59type _[P *T | T | struct{} | T] struct{}
    60type _[P <-chan int] struct{}
    61type _[P *T | struct{} | T] struct{}
    62
    63// a trailing comma always indicates a (possibly invalid) type parameter list (blank after type parameter list and type)
    64type _[P *T,] struct{}
    65type _[P *T | T,] struct{}
    66type _[P *T | <-T | T,] struct{}
    67
    68// slice/array type declarations (no blank between array length and element type)
    69type _ []byte
    70type _ [n]byte
    71type _ [P(T)]byte
    72type _ [P((T))]byte
    73type _ [P * *T]byte
    74type _ [P * T]byte
    75type _ [P(*T)]byte
    76type _ [P(**T)]byte
    77type _ [P * T - T]byte
    78type _ [P * T - T]byte
    79type _ [P * T | T]byte
    80type _ [P * T | <-T | T]byte
    81
    82// equivalent test cases for potentially ambiguous type parameter lists, except
    83// for function declarations there is no ambiguity (issue #51548)
    84func _[P *T,]() {}
    85func _[P *T, _ any]() {}
    86func _[P (*T),]() {}
    87func _[P (*T), _ any]() {}
    88func _[P (T),]() {}
    89func _[P (T), _ any]() {}
    90
    91func _[P *struct{}] () {}
    92func _[P (*struct{})] () {}
    93func _[P ([]int)] () {}
    94
    95func _ [P(T)]() {}
    96func _ [P((T))]() {}
    97func _ [P * *T]() {}
    98func _ [P * T]() {}
    99func _ [P(*T)]() {}
   100func _ [P(**T)]() {}
   101func _ [P * T]() {}
   102
   103func _[
   104	P *T,
   105]() {}

View as plain text