From 1731d4ec86f6922520af0c49df654a99285702fc Mon Sep 17 00:00:00 2001 From: Marco Date: Sun, 27 Jun 2021 11:29:10 +0200 Subject: [PATCH] compiler/ast,compiler/checker: make struct literal errors the same as gc This change implements the commit golang/go@2c95e3a6a8377ca9c72608c25b4cf2506baf782f in Scriggo. For #385 --- compiler/ast/ast.go | 7 ++- compiler/checker_expressions.go | 4 +- compiler/checker_template_test.go | 10 ++-- compiler/checker_test.go | 46 +++++++++---------- test/compare/testdata/fixedbugs/issue206.go | 2 +- .../testdata/github.com-golang-go/alias2.go | 10 ++-- .../fixedbugs/issue7921.go | 6 +-- .../oldescape_issue12006.go | 4 +- test/compare/testdata/misc/constant_errors.go | 24 +++++----- test/compare/testdata/misc/switch2.go | 4 +- test/compare/testdata/types/alias.go | 4 +- test/compare/testdata/types/assignments.go | 22 ++++----- .../compare/testdata/types/composite_types.go | 4 +- 13 files changed, 75 insertions(+), 72 deletions(-) diff --git a/compiler/ast/ast.go b/compiler/ast/ast.go index 3a58aed67..b32232a3b 100644 --- a/compiler/ast/ast.go +++ b/compiler/ast/ast.go @@ -1116,8 +1116,8 @@ func NewCompositeLiteral(pos *Position, typ Expression, keyValues []KeyValue) *C } func (n *CompositeLiteral) String() string { + s := n.Type.String() if expandedPrint { - s := n.Type.String() s += "{" for i, kv := range n.KeyValues { if i > 0 { @@ -1128,7 +1128,10 @@ func (n *CompositeLiteral) String() string { s += "}" return s } - return n.Type.String() + " literal" + if len(n.KeyValues) > 0 { + return s + "{...}" + } + return s + "{}" } // KeyValue represents a key value pair in a slice, map or struct composite literal. diff --git a/compiler/checker_expressions.go b/compiler/checker_expressions.go index 5c47a172d..253fc8fbd 100644 --- a/compiler/checker_expressions.go +++ b/compiler/checker_expressions.go @@ -2117,10 +2117,10 @@ func (tc *typechecker) checkCompositeLiteral(node *ast.CompositeLiteral, typ ref return ti } if len(node.KeyValues) < ti.Type.NumField() { - panic(tc.errorf(node, "too few values in %s literal", ti)) + panic(tc.errorf(node, "too few values in %s{...}", ti)) } if len(node.KeyValues) > ti.Type.NumField() { - panic(tc.errorf(node, "too many values in %s literal", ti)) + panic(tc.errorf(node, "too many values in %s{...}", ti)) } for i := range node.KeyValues { keyValue := &node.KeyValues[i] diff --git a/compiler/checker_template_test.go b/compiler/checker_template_test.go index 0e3eace39..40810959c 100644 --- a/compiler/checker_template_test.go +++ b/compiler/checker_template_test.go @@ -214,10 +214,10 @@ var checkerTemplateExprErrors = []struct { }{ // contains - {`[]byte{} contains "a"`, tierr(1, 13, `invalid operation: []byte literal contains "a" (cannot convert a (type untyped string) to type uint8)`), nil}, - {`[]int{} contains int32(5)`, tierr(1, 12, `invalid operation: []int literal contains int32(5) (mismatched types int and rune)`), nil}, - {`[]int{} contains i`, tierr(1, 12, `invalid operation: []int literal contains i (mismatched types int and compiler.definedInt)`), map[string]*typeInfo{"i": definedIntTypeInfo}}, - {`[2]int{0,1} contains rune('a')`, tierr(1, 16, `invalid operation: [2]int literal contains rune('a') (mismatched types int and rune)`), nil}, + {`[]byte{} contains "a"`, tierr(1, 13, `invalid operation: []byte{} contains "a" (cannot convert a (type untyped string) to type uint8)`), nil}, + {`[]int{} contains int32(5)`, tierr(1, 12, `invalid operation: []int{} contains int32(5) (mismatched types int and rune)`), nil}, + {`[]int{} contains i`, tierr(1, 12, `invalid operation: []int{} contains i (mismatched types int and compiler.definedInt)`), map[string]*typeInfo{"i": definedIntTypeInfo}}, + {`[2]int{0,1} contains rune('a')`, tierr(1, 16, `invalid operation: [2]int{...} contains rune('a') (mismatched types int and rune)`), nil}, // macro type literal {`(macro() css)(nil)`, tierr(1, 13, `invalid macro result type css`), map[string]*typeInfo{"css": {Type: reflect.TypeOf(0), Properties: propertyIsType}}}, @@ -544,7 +544,7 @@ var checkerTemplateStmts = []struct { {src: `{%% for _ in (&[...]int{}) { } %%}`, expected: ok}, {src: `{%% for a in make(<-chan string) { var _ string = a } %%}`, expected: ok}, {src: `{%% for _ in 0 { } %%}`, expected: `cannot range over 0 (type untyped number)`}, - {src: `{%% for _ in (&[]int{}) { } %%}`, expected: `cannot range over &[]int literal (type *[]int)`}, + {src: `{%% for _ in (&[]int{}) { } %%}`, expected: `cannot range over &[]int{} (type *[]int)`}, {src: `{%% for a, b in "" { } %%}`, expected: `unexpected in, expecting := or = or comma`}, // should be better 'too many variables in range'. {src: `{%% for a in nil { } %%}`, expected: `cannot range over nil`}, {src: `{%% for a in _ { } %%}`, expected: `cannot use _ as value`}, diff --git a/compiler/checker_test.go b/compiler/checker_test.go index 2f8920e79..961cc6ad5 100644 --- a/compiler/checker_test.go +++ b/compiler/checker_test.go @@ -816,7 +816,7 @@ var checkerStmts = map[string]string{ `a := 1; _ = a % 0`: `division by zero`, // Equality - `type S = struct{ A func() }; _ = interface{}(nil) == S{}`: `invalid operation: interface{}(nil) == S literal (struct { A func() } cannot be compared)`, + `type S = struct{ A func() }; _ = interface{}(nil) == S{}`: `invalid operation: interface{}(nil) == S{} (struct { A func() } cannot be compared)`, `var a interface{}; _ = a == 9223372036854775808`: `invalid operation: a == 9223372036854775808 (constant 9223372036854775808 overflows int)`, // Other comparisons @@ -868,7 +868,7 @@ var checkerStmts = map[string]string{ `v := 1; v &^= 2`: ok, `v := 1; v <<= 2`: ok, `v := 1; v >>= 2`: ok, - `[]int{1,2,3} := 3`: `non-name []int literal on left side of :=`, + `[]int{1,2,3} := 3`: `non-name []int{...} on left side of :=`, `a := 0; *a = 1`: `invalid indirect of a (type int)`, `a := 0; b := &a; b[0] = 2`: `invalid operation: b[0] (type *int does not support indexing)`, `a := 1; a, a = 1, 2`: declaredNotUsed("a"), @@ -883,7 +883,7 @@ var checkerStmts = map[string]string{ `v1 := 1; v2 := "a"; v1 = v2`: `cannot use v2 (type string) as type int in assignment`, `v := "a"; v[0] = 'b'`: `cannot assign to v[0]`, `v := [...]int{}; v[0] = 5`: ok, - `([1]int{0})[0] = 1`: `cannot assign to [1]int literal[0]`, + `([1]int{0})[0] = 1`: `cannot assign to [1]int{...}[0]`, `m := map[int]struct{A int}{}; m[0].A = 5`: `cannot assign to struct field m[0].A in map`, `m := map[int]*struct{A int}{}; m[0].A = 5`: ok, `v := "a"; v[0]++`: `cannot assign to v[0]`, @@ -892,7 +892,7 @@ var checkerStmts = map[string]string{ `v := []int{}; v[0]++`: ok, `v := &[1]int{}; v[0]++`: ok, `([]int{0})[0]++`: ok, - `([1]int{0})[0]++`: `cannot assign to [1]int literal[0]`, + `([1]int{0})[0]++`: `cannot assign to [1]int{...}[0]`, `v := map[int]int{}; v[0]++`: ok, `(map[int]int{})[0]++`: ok, `(func(){})()++`: `func literal() used as value`, // TODO: gc returns `(func literal)() used as value` @@ -914,7 +914,7 @@ var checkerStmts = map[string]string{ // Slicing `_ = []int{1,2,3,4,5}[:]`: ok, - `_ = [5]int{1,2,3,4,5}[:]`: `invalid operation [5]int literal[:] (slice of unaddressable value)`, + `_ = [5]int{1,2,3,4,5}[:]`: `invalid operation [5]int{...}[:] (slice of unaddressable value)`, `a := [5]int{1,2,3,4,5}; _ = a[:]`: ok, `_ = "abcde"[:]`: ok, `_ = []int{1,2,3,4,5}[:1:2]`: ok, @@ -933,7 +933,7 @@ var checkerStmts = map[string]string{ `v := <-aIntChan; _ = v`: ok, `v, ok := <-aIntChan; _, _ = v, ok`: ok, `_ = <-5`: `invalid operation: <-5 (receive from non-chan type int)`, - `_ = <-[]struct{A int}{{A: 5}}`: `invalid operation: <-[]struct { A int } literal (receive from non-chan type []struct { A int })`, + `_ = <-[]struct{A int}{{A: 5}}`: `invalid operation: <-[]struct { A int }{...} (receive from non-chan type []struct { A int })`, `var ch chan<- int; _ = <-ch`: `invalid operation: <-ch (receive from send-only type chan<- int)`, `var f func() chan<- int; _ = <-f()`: `invalid operation: <-f() (receive from send-only type chan<- int)`, `_ = <-make(chan<- int)`: `invalid operation: <-(make(chan<- int)) (receive from send-only type chan<- int)`, @@ -945,7 +945,7 @@ var checkerStmts = map[string]string{ `aIntChan <- 1.34`: `constant 1.34 truncated to integer`, `aIntChan <- "a"`: `cannot convert "a" (type untyped string) to type int`, `make(<-chan int) <- 5`: `invalid operation: make(<-chan int) <- 5 (send to receive-only type <-chan int)`, - `[]struct{A int}{{A: 5}} <- 5`: `invalid operation: []struct { A int } literal <- 5 (send to non-chan type []struct { A int })`, + `[]struct{A int}{{A: 5}} <- 5`: `invalid operation: []struct { A int }{...} <- 5 (send to non-chan type []struct { A int })`, `aSliceChan <- nil`: ok, `aSliceChan <- []int(nil)`: ok, `aSliceChan <- []int{1}`: ok, @@ -999,7 +999,7 @@ var checkerStmts = map[string]string{ `_ = [][]string{[]string{"a", "f"}, []string{"g", "h"}}`: ok, `_ = []int{}`: ok, `_ = []int{1,2,3}`: ok, - `_ = [][]int{[]string{"a", "f"}, []string{"g", "h"}}`: `cannot use []string literal (type []string) as type []int in slice literal`, + `_ = [][]int{[]string{"a", "f"}, []string{"g", "h"}}`: `cannot use []string{...} (type []string) as type []int in slice literal`, `_ = []int{-3: 9}`: `index must be non-negative integer constant`, `_ = []int{"a"}`: `cannot use "a" (type untyped string) as type int in slice literal`, `_ = []int{1:10, 1:20}`: `duplicate index in slice literal: 1`, @@ -1020,8 +1020,8 @@ var checkerStmts = map[string]string{ `_ = map[string]string{}`: ok, `_ = map[bool][]int{true: []int{1, 2, 3}}`: ok, `_ = map[bool][]int{4: []int{1, 2, 3}}`: `cannot use 4 (type untyped int) as type bool in map key`, - `_ = map[int]int{1: 3, 1: 4} `: `duplicate key 1 in map literal`, - `_ = map[string]int{"a": 3, "a": 4} `: `duplicate key "a" in map literal`, + `_ = map[int]int{1: 3, 1: 4}`: `duplicate key 1 in map literal`, + `_ = map[string]int{"a": 3, "a": 4}`: `duplicate key "a" in map literal`, `_ = map[string]string{"k1": 2}`: `cannot use 2 (type untyped int) as type string in map value`, `_ = map[string]string{2: "v1"}`: `cannot use 2 (type untyped int) as type string in map key`, @@ -1037,9 +1037,9 @@ var checkerStmts = map[string]string{ `_ = pointInt{_:0, _:1}`: `invalid field name _ in struct initializer`, `_ = pointInt{"a", "b"}`: `cannot use "a" (type untyped string) as type int in field value`, `_ = pointInt{1, Y: 2}`: `mixture of field:value and value initializers`, - `_ = pointInt{1,2,3}`: `too many values in compiler.pointInt literal`, + `_ = pointInt{1,2,3}`: `too many values in compiler.pointInt{...}`, `_ = pointInt{1.2,2.0}`: `constant 1.2 truncated to integer`, - `_ = pointInt{1}`: `too few values in compiler.pointInt literal`, + `_ = pointInt{1}`: `too few values in compiler.pointInt{...}`, `_ = pointInt{X: "a", Y: "b"}`: `cannot use "a" (type untyped string) as type int in field value`, `_ = pointInt{X: 1, 2}`: `mixture of field:value and value initializers`, `_ = pointInt{X: 2, X: 2}`: `duplicate field name in struct literal: X`, @@ -1051,7 +1051,7 @@ var checkerStmts = map[string]string{ `type S struct{F int}; var x S; _ = x.F`: ok, `type S *struct{F int}; var x S; _ = (*x).F`: ok, `type S *struct{F int}; var x S; _ = x.F`: ok, - `type S struct{F int}; _ = &(S{}.F)`: `cannot take the address of S literal.F`, + `type S struct{F int}; _ = &(S{}.F)`: `cannot take the address of S{}.F`, `type S *struct{F int}; _ = &((*S(nil)).F)`: ok, `type S *struct{F int}; _ = &(S(nil).F)`: ok, `type S struct{F int}; var x S; _ = &(x.F)`: ok, @@ -1060,8 +1060,8 @@ var checkerStmts = map[string]string{ // Struct fields and methods. `(&pointInt{0,0}).SetX(10)`: ok, - `(&pointInt{0,0}).SetZ(10)`: `&pointInt literal.SetZ undefined (type *compiler.pointInt has no field or method SetZ)`, // TODO (Gianluca): 'pointInt literal' should be '(compiler.pointInt literal)' - `(pointInt{0,0}).SetZ(10)`: `pointInt literal.SetZ undefined (type compiler.pointInt has no field or method SetZ)`, // TODO (Gianluca): 'pointInt literal' should be '(compiler.pointInt literal)' + `(&pointInt{0,0}).SetZ(10)`: `&pointInt{...}.SetZ undefined (type *compiler.pointInt has no field or method SetZ)`, // TODO (Gianluca): 'pointInt{...}' should be '(compiler.pointInt{...})' + `(pointInt{0,0}).SetZ(10)`: `pointInt{...}.SetZ undefined (type compiler.pointInt has no field or method SetZ)`, // TODO (Gianluca): 'pointInt{...}' should be '(compiler.pointInt{...})' `nil.SetZ()`: `use of untyped nil`, // Interfaces. @@ -1077,8 +1077,8 @@ var checkerStmts = map[string]string{ // Note that for strings gc returns the two errors // `cannot convert "" (type untyped string) to type int` and `cannot convert nil to type int`. `_ = [1]int{} == nil`: `cannot convert nil to type [1]int`, - `_ = []int{} < nil`: `invalid operation: []int literal < nil (operator < not defined on slice)`, - `_ = map[string]string{} < nil`: `invalid operation: map[string]string literal < nil (operator < not defined on map)`, + `_ = []int{} < nil`: `invalid operation: []int{} < nil (operator < not defined on slice)`, + `_ = map[string]string{} < nil`: `invalid operation: map[string]string{} < nil (operator < not defined on map)`, // Expressions. `int + 2`: `type int is not an expression`, @@ -1179,7 +1179,7 @@ var checkerStmts = map[string]string{ `for k, v := range map[float64]string{} { var _ float64 = k; var _ string = v }`: ok, `for _, _ = range (&[...]int{}) { }`: ok, `for _, _ = range 0 { }`: `cannot range over 0 (type untyped number)`, - `for _, _ = range (&[]int{}) { }`: `cannot range over &[]int literal (type *[]int)`, + `for _, _ = range (&[]int{}) { }`: `cannot range over &[]int{} (type *[]int)`, `for a, b, c := range "" { }`: `too many variables in range`, `for a, b := range nil { }`: `cannot range over nil`, `for a, b := range _ { }`: `cannot use _ as value`, @@ -1361,7 +1361,7 @@ var checkerStmts = map[string]string{ `f := func(a int, b...int) { b[0] = 1 }; f(1); f(1); f(1,2,3)`: ok, `f := func(a... int) { a[0] = 1 }; f([]int{1,2,3}...)`: ok, `f := func(a... int) { a[0] = 1 }; f(); f(1); f(1,2,3)`: ok, - `f := func(a... int) { a[0] = 1 }; f([]string{"1","2","3"}...)`: `cannot use []string literal (type []string) as type []int in argument to f`, + `f := func(a... int) { a[0] = 1 }; f([]string{"1","2","3"}...)`: `cannot use []string{...} (type []string) as type []int in argument to f`, `f := func(a... int) { a[0] = 1 }; var a int; f(a...)`: `cannot use a (type int) as type []int in argument to f`, `f := func(a, b, c int, d... int) { }; f(1,2)`: "not enough arguments in call to f\n\thave (number, number)\n\twant (int, int, int, ...int)", @@ -1436,7 +1436,7 @@ var checkerStmts = map[string]string{ `_ = append + 3`: `use of builtin append not in function call`, `a, b := append([]int{}, 0)`: `assignment mismatch: 2 variables but 1 values`, `append()`: `missing arguments to append`, - `append([]int{}, 0)`: evaluatedButNotUsed("append([]int literal, 0)"), + `append([]int{}, 0)`: evaluatedButNotUsed("append([]int{}, 0)"), `append(0)`: `first argument to append must be slice; have untyped number`, `append(nil)`: `first argument to append must be typed slice; have untyped nil`, `append([]string{}, nil)`: `cannot use nil as type string in append`, @@ -1473,7 +1473,7 @@ var checkerStmts = map[string]string{ // Builtin function 'len'. `_ = len([]int{})`: ok, `len()`: `missing argument to len: len()`, - `len([]string{"", ""})`: evaluatedButNotUsed("len([]string literal)"), + `len([]string{"", ""})`: evaluatedButNotUsed("len([]string{...})"), `len(0)`: `invalid argument 0 (type int) for len`, `len(nil)`: `use of untyped nil`, `len := 0; _ = len`: ok, @@ -1489,8 +1489,8 @@ var checkerStmts = map[string]string{ `cap()`: `missing argument to cap: cap()`, `cap(0)`: `invalid argument 0 (type int) for cap`, `cap(nil)`: `use of untyped nil`, - `cap([]int{})`: evaluatedButNotUsed("cap([]int literal)"), - `const _ = cap([]int{})`: `const initializer cap([]int literal) is not a constant`, + `cap([]int{})`: evaluatedButNotUsed("cap([]int{})"), + `const _ = cap([]int{})`: `const initializer cap([]int{}) is not a constant`, `const _ = cap(new([1]byte))`: `const initializer cap(new([1]byte)) is not a constant`, // Builtin function 'make'. diff --git a/test/compare/testdata/fixedbugs/issue206.go b/test/compare/testdata/fixedbugs/issue206.go index ff193af05..fc95b7e26 100644 --- a/test/compare/testdata/fixedbugs/issue206.go +++ b/test/compare/testdata/fixedbugs/issue206.go @@ -4,6 +4,6 @@ package main func len(s interface{}) int { return 0 } -const _ = len([1]int{}) // ERROR `const initializer len([1]int literal) is not a constant` +const _ = len([1]int{}) // ERROR `const initializer len([1]int{}) is not a constant` func main() {} diff --git a/test/compare/testdata/github.com-golang-go/alias2.go b/test/compare/testdata/github.com-golang-go/alias2.go index da380926f..94a58bc80 100644 --- a/test/compare/testdata/github.com-golang-go/alias2.go +++ b/test/compare/testdata/github.com-golang-go/alias2.go @@ -48,8 +48,8 @@ var _ A0 = T0{} var _ T0 = A0{} // But aliases and original types cannot be used with new types based on them. -var _ N0 = T0{} // ERROR "cannot use T0 literal \(type T0\) as type N0 in assignment|incompatible type" -var _ N0 = A0{} // ERROR "cannot use T0 literal \(type T0\) as type N0 in assignment|incompatible type" +var _ N0 = T0{} // ERROR "cannot use T0{} \(type T0\) as type N0 in assignment|incompatible type" +var _ N0 = A0{} // ERROR "cannot use T0{} \(type T0\) as type N0 in assignment|incompatible type" var _ A5 = Value{} @@ -84,10 +84,10 @@ func _() { var _ A0 = T0{} var _ T0 = A0{} - var _ N0 = T0{} // ERROR "cannot use T0 literal \(type T0\) as type N0 in assignment|incompatible type" - var _ N0 = A0{} // ERROR "cannot use T0 literal \(type T0\) as type N0 in assignment|incompatible type" + var _ N0 = T0{} // ERROR "cannot use T0{} \(type T0\) as type N0 in assignment|incompatible type" + var _ N0 = A0{} // ERROR "cannot use T0{} \(type T0\) as type N0 in assignment|incompatible type" - var _ A5 = Value{} // ERROR "cannot use reflect\.Value literal \(type reflect.Value\) as type A5 in assignment|incompatible type" + var _ A5 = Value{} // ERROR "cannot use reflect\.Value{} \(type reflect.Value\) as type A5 in assignment|incompatible type" } // Invalid type alias declarations. diff --git a/test/compare/testdata/github.com-golang-go/fixedbugs/issue7921.go b/test/compare/testdata/github.com-golang-go/fixedbugs/issue7921.go index 48cf97602..998382dc5 100644 --- a/test/compare/testdata/github.com-golang-go/fixedbugs/issue7921.go +++ b/test/compare/testdata/github.com-golang-go/fixedbugs/issue7921.go @@ -20,12 +20,12 @@ func bufferNotEscape() string { // can be stack-allocated. var b bytes.Buffer b.WriteString("123") - b.Write([]byte{'4'}) // ERROR "bufferNotEscape \[\]byte literal does not escape$" + b.Write([]byte{'4'}) // ERROR "bufferNotEscape \[\]byte{...} does not escape$" return b.String() // ERROR "inlining call to bytes.\(\*Buffer\).String$" "string\(bytes.b.buf\[bytes.b.off:\]\) escapes to heap$" } func bufferNoEscape2(xs []string) int { // ERROR "bufferNoEscape2 xs does not escape$" - b := bytes.NewBuffer(make([]byte, 0, 64)) // ERROR "bufferNoEscape2 &bytes.Buffer literal does not escape$" "bufferNoEscape2 make\(\[\]byte, 0, 64\) does not escape$" "inlining call to bytes.NewBuffer$" + b := bytes.NewBuffer(make([]byte, 0, 64)) // ERROR "bufferNoEscape2 &bytes.Buffer{...} does not escape$" "bufferNoEscape2 make\(\[\]byte, 0, 64\) does not escape$" "inlining call to bytes.NewBuffer$" for _, x := range xs { b.WriteString(x) } @@ -33,7 +33,7 @@ func bufferNoEscape2(xs []string) int { // ERROR "bufferNoEscape2 xs does not es } func bufferNoEscape3(xs []string) string { // ERROR "bufferNoEscape3 xs does not escape$" - b := bytes.NewBuffer(make([]byte, 0, 64)) // ERROR "bufferNoEscape3 &bytes.Buffer literal does not escape$" "bufferNoEscape3 make\(\[\]byte, 0, 64\) does not escape$" "inlining call to bytes.NewBuffer$" + b := bytes.NewBuffer(make([]byte, 0, 64)) // ERROR "bufferNoEscape3 &bytes.Buffer{...} does not escape$" "bufferNoEscape3 make\(\[\]byte, 0, 64\) does not escape$" "inlining call to bytes.NewBuffer$" for _, x := range xs { b.WriteString(x) b.WriteByte(',') diff --git a/test/compare/testdata/github.com-golang-go/oldescape_issue12006.go b/test/compare/testdata/github.com-golang-go/oldescape_issue12006.go index a9e5a25f6..e65375df2 100644 --- a/test/compare/testdata/github.com-golang-go/oldescape_issue12006.go +++ b/test/compare/testdata/github.com-golang-go/oldescape_issue12006.go @@ -146,7 +146,7 @@ func TFooK2() { a := int32(1) // ERROR "moved to heap: a" b := "cat" c := &a - fs := fakeSlice{3, &[4]interface{}{a, b, c, nil}} // ERROR "a escapes to heap" "b escapes to heap" "c escapes to heap" "TFooK2 &\[4\]interface {} literal does not escape" + fs := fakeSlice{3, &[4]interface{}{a, b, c, nil}} // ERROR "a escapes to heap" "b escapes to heap" "c escapes to heap" "TFooK2 &\[4\]interface {}{...} does not escape" isink = FooK(fs) } @@ -171,6 +171,6 @@ func TFooL2() { a := int32(1) // ERROR "moved to heap: a" b := "cat" c := &a - s := []interface{}{a, b, c} // ERROR "a escapes to heap" "b escapes to heap" "c escapes to heap" "TFooL2 \[\]interface {} literal does not escape" + s := []interface{}{a, b, c} // ERROR "a escapes to heap" "b escapes to heap" "c escapes to heap" "TFooL2 \[\]interface {}{...} does not escape" isink = FooL(s) } diff --git a/test/compare/testdata/misc/constant_errors.go b/test/compare/testdata/misc/constant_errors.go index fead5f4de..2a62d2802 100644 --- a/test/compare/testdata/misc/constant_errors.go +++ b/test/compare/testdata/misc/constant_errors.go @@ -10,22 +10,22 @@ func main() { _ = ch const _ = len(([]string)(nil)[0]) // ERROR `const initializer len([]string(nil)[0]) is not a constant` - const _ = len([1]int{<-ch}) // ERROR `const initializer len([1]int literal) is not a constant` - const _ = len([1]int{1 * (2 - <-ch)}) // ERROR `const initializer len([1]int literal) is not a constant` + const _ = len([1]int{<-ch}) // ERROR `const initializer len([1]int{...}) is not a constant` + const _ = len([1]int{1 * (2 - <-ch)}) // ERROR `const initializer len([1]int{...}) is not a constant` const _ = len(new([1]int)) // ERROR `const initializer len(new([1]int)) is not a constant` const _ = len(<-make(chan [1]int, 1)) // ERROR `const initializer len(<-make(chan [1]int, 1)) is not a constant` - const _ = len([3]int{f()}) // ERROR `const initializer len([3]int literal) is not a constant` - const _ = len([1][]int{append([]int{}, 0)}) // ERROR `const initializer len([1][]int literal) is not a constant` - const _ = len([1]int{copy([]int{}, []int{})}) // ERROR `const initializer len([1]int literal) is not a constant` - const _ = len([1]interface{}{recover()}) // ERROR `const initializer len([1]interface{} literal) is not a constant` + const _ = len([3]int{f()}) // ERROR `const initializer len([3]int{...}) is not a constant` + const _ = len([1][]int{append([]int{}, 0)}) // ERROR `const initializer len([1][]int{...}) is not a constant` + const _ = len([1]int{copy([]int{}, []int{})}) // ERROR `const initializer len([1]int{...}) is not a constant` + const _ = len([1]interface{}{recover()}) // ERROR `const initializer len([1]interface{}{...}) is not a constant` - const _ = cap([1]int{<-ch}) // ERROR `const initializer cap([1]int literal) is not a constant` - const _ = cap([1]int{1 * (2 - <-ch)}) // ERROR `const initializer cap([1]int literal) is not a constant` + const _ = cap([1]int{<-ch}) // ERROR `const initializer cap([1]int{...}) is not a constant` + const _ = cap([1]int{1 * (2 - <-ch)}) // ERROR `const initializer cap([1]int{...}) is not a constant` const _ = cap(new([1]int)) // ERROR `const initializer cap(new([1]int)) is not a constant` const _ = cap(<-make(chan [1]int, 1)) // ERROR `const initializer cap(<-make(chan [1]int, 1)) is not a constant` - const _ = cap([3]int{f()}) // ERROR `const initializer cap([3]int literal) is not a constant` - const _ = cap([1][]int{append([]int{}, 0)}) // ERROR `const initializer cap([1][]int literal) is not a constant` - const _ = cap([1]int{copy([]int{}, []int{})}) // ERROR `const initializer cap([1]int literal) is not a constant` - const _ = cap([1]interface{}{recover()}) // ERROR `const initializer cap([1]interface{} literal) is not a constant` + const _ = cap([3]int{f()}) // ERROR `const initializer cap([3]int{...}) is not a constant` + const _ = cap([1][]int{append([]int{}, 0)}) // ERROR `const initializer cap([1][]int{...}) is not a constant` + const _ = cap([1]int{copy([]int{}, []int{})}) // ERROR `const initializer cap([1]int{...}) is not a constant` + const _ = cap([1]interface{}{recover()}) // ERROR `const initializer cap([1]interface{}{...}) is not a constant` } diff --git a/test/compare/testdata/misc/switch2.go b/test/compare/testdata/misc/switch2.go index f67f74738..7304b243a 100755 --- a/test/compare/testdata/misc/switch2.go +++ b/test/compare/testdata/misc/switch2.go @@ -50,8 +50,8 @@ func main() { switch b { case 5: } switch b { case 1 < 2: } switch b { case a < "b": } - switch b { case []int{}: } // ERROR `invalid case []int literal (type []int) in switch (incomparable type)` - switch []int{} { case []int{}: } // ERROR `invalid case []int literal in switch (can only compare slice []int literal to nil)` + switch b { case []int{}: } // ERROR `invalid case []int{} (type []int) in switch (incomparable type)` + switch []int{} { case []int{}: } // ERROR `invalid case []int{} in switch (can only compare slice []int{} to nil)` switch b { case b: } switch f { case f: } // ERROR `invalid case f in switch (can only compare func f to nil)` switch f { case nil: } diff --git a/test/compare/testdata/types/alias.go b/test/compare/testdata/types/alias.go index 238ea22ee..a6578c983 100644 --- a/test/compare/testdata/types/alias.go +++ b/test/compare/testdata/types/alias.go @@ -9,14 +9,14 @@ func main() { type SliceString = []string var _ SliceString = []string{} - var _ SliceString = []int{} // ERROR `cannot use []int literal (type []int) as type []string in assignment` + var _ SliceString = []int{} // ERROR `cannot use []int{} (type []int) as type []string in assignment` type Int2 = int var _ Int2 = Int(0) var _ Int2 = int(0) var _ Int2 = Int2(0) var _ Int2 = 0 - var _ Int2 = SliceString{} // ERROR `cannot use SliceString literal (type []string) as type int in assignment` + var _ Int2 = SliceString{} // ERROR `cannot use SliceString{} (type []string) as type int in assignment` var _ Int2 = string(30) // ERROR `cannot use string(30) (type string) as type int in assignment` var _ Int2 = int32(0) // ERROR `cannot use int32(0) (type int32) as type int in assignment` } diff --git a/test/compare/testdata/types/assignments.go b/test/compare/testdata/types/assignments.go index 892c0f3ac..f2fdef687 100644 --- a/test/compare/testdata/types/assignments.go +++ b/test/compare/testdata/types/assignments.go @@ -7,7 +7,7 @@ func arrayTypes() { var a1 [3]Int1 _ = a1 a1[0] = int(0) // ERROR `cannot use int(0) (type int) as type Int1 in assignment` - a1 = [3]int{} // ERROR `cannot use [3]int literal (type [3]int) as type [3]Int1 in assignment` + a1 = [3]int{} // ERROR `cannot use [3]int{} (type [3]int) as type [3]Int1 in assignment` } func chanTypes() { @@ -33,7 +33,7 @@ func chanTypes() { var c3 chan<- []String _ = c3 - c3 <- []Int{} // ERROR `cannot use []Int literal (type []Int) as type []String in send` + c3 <- []Int{} // ERROR `cannot use []Int{} (type []Int) as type []String in send` var c4 (<-chan map[String][]Int) _ = c4 @@ -77,9 +77,9 @@ func mapTypes() { var m MapIntString _ = m - m = map[int]int{} // ERROR `cannot use map[int]int literal (type map[int]int) as type MapIntString in assignment` - m = map[Int]String{} // ERROR `cannot use map[Int]String literal (type map[Int]String) as type MapIntString in assignment` - m = []MapIntString{} // ERROR `cannot use []MapIntString literal (type []MapIntString) as type MapIntString in assignment` + m = map[int]int{} // ERROR `cannot use map[int]int{} (type map[int]int) as type MapIntString in assignment` + m = map[Int]String{} // ERROR `cannot use map[Int]String{} (type map[Int]String) as type MapIntString in assignment` + m = []MapIntString{} // ERROR `cannot use []MapIntString{} (type []MapIntString) as type MapIntString in assignment` } func sliceTypes() { @@ -87,8 +87,8 @@ func sliceTypes() { type String string var s []Int _ = s - s = []int{} // ERROR `cannot use []int literal (type []int) as type []Int in assignment` - s = []String{} // ERROR `cannot use []String literal (type []String) as type []Int in assignment` + s = []int{} // ERROR `cannot use []int{} (type []int) as type []Int in assignment` + s = []String{} // ERROR `cannot use []String{} (type []String) as type []Int in assignment` } func ptrTypes() { @@ -112,17 +112,17 @@ func structTypes() { _ = s //s.A = 4 // ERROR `cannot use 4 s(type int) as type map[Int][]string in assignment` TODO //s.A = String("ciao") // ERROR `cannot use String("ciao") (type String) as type map[Int][]string in assignment` - //s = []int{} // ERROR `cannot use []int literal (type []int) as type struct { A map[Int][]string; B map[Int][]string } in assignment` + //s = []int{} // ERROR `cannot use []int{} (type []int) as type struct { A map[Int][]string; B map[Int][]string } in assignment` type S struct{ A map[string]Field } var s2 S _ = s2 //s2.A = 4 // ERROR `cannot use 4 (type int) as type map[string]map[Int][]string in assignment` - //s2.A = map[string]Int{} // ERROR `cannot use map[string]Int literal (type map[string]Int) as type map[string]map[Int][]string in assignment` + //s2.A = map[string]Int{} // ERROR `cannot use map[string]Int{} (type map[string]Int) as type map[string]map[Int][]string in assignment` type F struct{ A []Field } - // s2 = F{} // ERROR `cannot use F literal (type F) as type S in assignment` - // s2 = struct{ A []Field }{} // ERROR `cannot use struct { A []Field } literal (type struct { A []map[Int][]string }) as type S in assignment` + // s2 = F{} // ERROR `cannot use F{} (type F) as type S in assignment` + // s2 = struct{ A []Field }{} // ERROR `cannot use struct { A []Field }{} (type struct { A []map[Int][]string }) as type S in assignment` } func main() { diff --git a/test/compare/testdata/types/composite_types.go b/test/compare/testdata/types/composite_types.go index 169690a67..882ba44aa 100644 --- a/test/compare/testdata/types/composite_types.go +++ b/test/compare/testdata/types/composite_types.go @@ -5,9 +5,9 @@ package main func main() { type Int int - var _ []Int = []int{1, 2, 3} // ERROR `cannot use []int literal (type []int) as type []Int in assignment` + var _ []Int = []int{1, 2, 3} // ERROR `cannot use []int{...} (type []int) as type []Int in assignment` - var _ []int = []Int{3, 4, 5} // ERROR `cannot use []Int literal (type []Int) as type []int in assignment` + var _ []int = []Int{3, 4, 5} // ERROR `cannot use []Int{...} (type []Int) as type []int in assignment` type SliceInt1 []Int var s1 SliceInt1