Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
alias2.go105 linesDownload Raw Back to test
1// errorcheck2 3// Copyright 2016 The Go Authors. All rights reserved.4// Use of this source code is governed by a BSD-style5// license that can be found in the LICENSE file.6 7// Test basic restrictions on type aliases.8 9package p10 11import (12	"reflect"13	. "reflect"14)15 16type T0 struct{}17 18// Valid type alias declarations.19 20type _ = T021type _ = int22type _ = struct{}23type _ = reflect.Value24type _ = Value25 26type (27	A0 = T028	A1 = int29	A2 = struct{}30	A3 = reflect.Value31	A4 = Value32	A5 = Value33 34	N0 A035)36 37// Methods can be declared on the original named type and the alias.38func (T0) m1()  {} // GCCGO_ERROR "previous"39func (*T0) m1() {} // ERROR "method redeclared: T0\.m1|T0\.m1 already declared|redefinition of .m1."40func (A0) m1()  {} // ERROR "T0\.m1 already declared|redefinition of .m1."41func (A0) m1()  {} // ERROR "T0\.m1 already declared|redefinition of .m1."42func (A0) m2()  {}43 44// Type aliases and the original type name can be used interchangeably.45var _ A0 = T0{}46var _ T0 = A0{}47 48// But aliases and original types cannot be used with new types based on them.49var _ N0 = T0{} // ERROR "cannot use T0{} \(value of struct type T0\) as N0 value in variable declaration"50var _ N0 = A0{} // ERROR "cannot use A0{} \(value of struct type A0\) as N0 value in variable declaration"51 52var _ A5 = Value{}53 54var _ interface {55	m1()56	m2()57} = T0{}58 59var _ interface {60	m1()61	m2()62} = A0{}63 64func _() {65	type _ = T066	type _ = int67	type _ = struct{}68	type _ = reflect.Value69	type _ = Value70 71	type (72		A0 = T073		A1 = int74		A2 = struct{}75		A3 = reflect.Value76		A4 = Value77		A5 Value78 79		N0 A080	)81 82	var _ A0 = T0{}83	var _ T0 = A0{}84 85	var _ N0 = T0{} // ERROR "cannot use T0{} \(value of struct type T0\) as N0 value in variable declaration"86	var _ N0 = A0{} // ERROR "cannot use A0{} \(value of struct type A0\) as N0 value in variable declaration"87 88	var _ A5 = Value{} // ERROR "cannot use Value{} \(value of struct type reflect\.Value\) as A5 value in variable declaration"89}90 91// Invalid type alias declarations.92 93type _ = reflect.ValueOf // ERROR "reflect.ValueOf .*is not a type|expected type"94 95func (A1) m() {} // ERROR "cannot define new methods on non-local type|may not define methods on non-local type"96func (A2) m() {} // ERROR "invalid receiver type"97func (A3) m() {} // ERROR "cannot define new methods on non-local type|may not define methods on non-local type"98func (A4) m() {} // ERROR "cannot define new methods on non-local type|may not define methods on non-local type"99 100type B1 = struct{}101 102func (B1) m() {} // ERROR "invalid receiver type"103 104// TODO(gri) expand105 
codekingpro/portable-devtools · Team Ai