Commit graph

14 commits

Author SHA1 Message Date
Robert Griesemer e22af33b48 go/types, types2: more concise error messages for cycle errors
If a cycle has length 1, don't enumerate the single cycle entry;
instead just mention "refers to itself". For instance, for an
invalid recursive type T we now report:

	invalid recursive type: T refers to itself

instead of:

	invalid recursive type T
		T refers to
		T

Adjust tests to check for the different error messages.

Change-Id: I5bd46f62fac0cf167f0d0c9a55f952981d294ff4
Reviewed-on: https://go-review.googlesource.com/c/go/+/436295
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Robert Griesemer <gri@google.com>
2022-09-29 14:21:33 +00:00
Dan Scales 90a8482a17 test: re-enable most go/tests that were disabled because of types2 differences
I made the default be that, where there are differences between types2
and -G=0 error messages, we want errorcheck tests to pass types2.
Typically, we can get errorcheck to pass on types2 and -G=0 if they give
the same number of error messages on the same lines, just different
wording. If they give a different number of error messages, then I made
types2 pass. I added an exception list for -G=0 to cover those cases
where -G=0 and types give different numbers of error messages.

Because types2 does not run if there are syntax errors, for several
tests, I had to split the tests into two parts in order to get all the
indicated errors to be reported in types2 (bug228.go, bug388.go,
issue11610.go, issue14520.go)

I tried to preserve the GCCGO labeling correctly (but may have gotten
some wrong). When types2 now matches where a GCCGO error previously
occurred, I transformed GCCGO_ERROR -> ERROR. When types2 no longer
reports an error in a certain place, I transformed ERROR -> GCCGO_ERROR.
When types2 reports an error in a new place, I used GC_ERROR.

The remaining entries in types2Failures are things that I think we
probably still need to fix - either actually missing errors in types2,
or cases where types2 gives worse errors than -G=0.

Change-Id: I7f01e82b322b16094096b67d7ed2bb39b410c34f
Reviewed-on: https://go-review.googlesource.com/c/go/+/372854
Trust: Dan Scales <danscales@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2022-01-11 02:26:58 +00:00
Dan Scales fd54ae8b0c [dev.typeparams] cmd/compile: adding union support in types1
Add union support in types1, and allow exporting of unions, and
importing unions back into types1 and types2.

Added new test mincheck.go/mincheck.dir that tests that type lists (type
sets) are correctly exported/imported, so that types2 gives correct
errors that an instantiation doesn't fit the type list in the type param
constraint.

Change-Id: I8041c6c79289c870a95ed5a1b10e4c1c16985b12
Reviewed-on: https://go-review.googlesource.com/c/go/+/322609
Trust: Dan Scales <danscales@google.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-05-26 15:33:02 +00:00
Ian Lance Taylor 731bb54038 test: update for gofrontend error message changes
fixedbugs/bug195.go:9:20: error: interface contains embedded non-interface
fixedbugs/bug195.go:12:20: error: interface contains embedded non-interface
fixedbugs/bug195.go:15:22: error: interface contains embedded non-interface
fixedbugs/bug195.go:18:9: error: invalid recursive interface
fixedbugs/bug195.go:26:9: error: invalid recursive interface

fixedbugs/bug251.go:15:9: error: invalid recursive interface

fixedbugs/issue23823.go:15:9: error: invalid recursive interface

Change-Id: If4c22430557459d5b361beda7168f8cb42b58811
Reviewed-on: https://go-review.googlesource.com/c/go/+/278512
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-12-15 21:45:05 +00:00
Matthew Dempsky 0e85fd7561 cmd/compile: report type loop for invalid recursive types
Similar to how we report initialization loops in initorder.go and type
alias loops in typecheck.go, this CL updates align.go to warn about
invalid recursive types. The code is based on the loop code from
initorder.go, with minimal changes to adapt from detecting
variable/function initialization loops to detecting type declaration
loops.

Thanks to Cuong Manh Le for investigating this, helping come up with
test cases, and exploring solutions.

Fixes #41575
Updates #41669.

Change-Id: Idb2cb8c5e1d645e62900e178fcb50af33e1700a1
Reviewed-on: https://go-review.googlesource.com/c/go/+/258177
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Trust: Matthew Dempsky <mdempsky@google.com>
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2020-09-29 22:49:58 +00:00
Matthew Dempsky 380ef6b759 cmd/compile: simplify {defer,resume}checkwidth logic
This CL extends {defer,resume}checkwidth to support nesting, which
simplifies usage.

Updates #33658.

Change-Id: Ib3ffb8a7cabfae2cbeba74e21748c228436f4726
Reviewed-on: https://go-review.googlesource.com/c/go/+/192721
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
2019-09-03 17:38:32 +00:00
Matthew Dempsky 07de3465be cmd/compile/internal/gc: handle recursive interfaces better
Previously, we handled recursive interfaces by deferring typechecking
of interface methods, while eagerly expanding interface embeddings.

This CL switches to eagerly evaluating interface methods, and
deferring expanding interface embeddings to dowidth. This allows us to
detect recursive interface embeddings with the same mechanism used for
detecting recursive struct embeddings.

Updates #16369.

Change-Id: If4c0320058047f8a2d9b52b9a79de47eb9887f95
Reviewed-on: https://go-review.googlesource.com/38391
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2017-03-21 01:56:25 +00:00
Russ Cox 2b1c9b4be2 test: use testlib (second 100)
X ,s;^// \$G (\$D/)?\$F\.go *$;// compile;g
X ,s;^// \$G (\$D/)?\$F\.go && \$L \$F\.\$A *$;// build;g
X ,s;^// \$G (\$D/)?\$F\.go && \$L \$F\.\$A && \./\$A\.out *$;// run;g
X ,s;^// errchk \$G( -e)? (\$D/)?\$F\.go *$;// errorcheck;g

R=golang-dev
CC=golang-dev
https://golang.org/cl/5673078
2012-02-16 23:49:30 -05:00
Ian Lance Taylor d5b7c5157e test: match gccgo error messages
complit1.go:37:34: error: may only omit types within composite literals of slice, array, or map type
complit1.go:38:19: error: may only omit types within composite literals of slice, array, or map type
complit1.go:18:21: error: slice of unaddressable value
complit1.go:19:10: error: slice of unaddressable value
complit1.go:20:9: error: slice of unaddressable value

convert1.go:28:13: error: invalid type conversion
convert1.go:32:12: error: invalid type conversion (cannot use type string as type Tint64)
convert1.go:36:12: error: invalid type conversion
convert1.go:37:13: error: invalid type conversion
convert1.go:40:11: error: invalid type conversion
convert1.go:41:12: error: invalid type conversion
convert1.go:44:12: error: invalid type conversion
convert1.go:46:13: error: invalid type conversion
convert1.go:48:11: error: invalid type conversion
convert1.go:50:12: error: invalid type conversion
convert1.go:52:6: error: invalid type conversion
convert1.go:53:12: error: invalid type conversion
convert1.go:54:12: error: invalid type conversion
convert1.go:56:13: error: invalid type conversion
convert1.go:57:11: error: invalid type conversion
convert1.go:58:11: error: invalid type conversion
convert1.go:64:13: error: invalid type conversion
convert1.go:68:12: error: invalid type conversion (cannot use type Tstring as type Tint64)
convert1.go:72:12: error: invalid type conversion
convert1.go:73:13: error: invalid type conversion
convert1.go:76:11: error: invalid type conversion (cannot use type Tbyte as type Trune)
convert1.go:77:12: error: invalid type conversion (cannot use type Tbyte as type Tint64)
convert1.go:80:12: error: invalid type conversion
convert1.go:82:13: error: invalid type conversion
convert1.go:84:11: error: invalid type conversion (cannot use type Trune as type Tbyte)
convert1.go:86:12: error: invalid type conversion (cannot use type Trune as type Tint64)
convert1.go:88:6: error: invalid type conversion (cannot use type Tint64 as type string)
convert1.go:89:12: error: invalid type conversion
convert1.go:90:12: error: invalid type conversion
convert1.go:92:13: error: invalid type conversion (cannot use type Tint64 as type Tstring)
convert1.go:93:11: error: invalid type conversion (cannot use type Tint64 as type Tbyte)
convert1.go:94:11: error: invalid type conversion (cannot use type Tint64 as type Trune)

fixedbugs/bug195.go:9:21: error: interface contains embedded non-interface
fixedbugs/bug195.go:12:21: error: interface contains embedded non-interface
fixedbugs/bug195.go:15:15: error: interface contains embedded non-interface
fixedbugs/bug195.go:18:2: error: invalid recursive interface
fixedbugs/bug195.go:26:2: error: invalid recursive interface
fixedbugs/bug195.go:22:2: error: invalid recursive interface

fixedbugs/bug251.go:15:2: error: invalid recursive interface
fixedbugs/bug251.go:11:2: error: invalid recursive interface

fixedbugs/bug374.go:18:34: error: use of undefined type ‘xxxx’
fixedbugs/bug374.go:16:5: error: incompatible type in initialization (incompatible type for method ‘m’ (different number of parameters))

fixedbugs/bug383.go:11:2: error: expected boolean expression
fixedbugs/bug383.go:12:2: error: expected boolean expression

fixedbugs/bug386.go:10:25: error: incompatible type for return value 1 (type has no methods)
fixedbugs/bug386.go:12:25: error: incompatible type for return value 1 (type has no methods)

fixedbugs/bug388.go:12:10: error: invalid named/anonymous mix
fixedbugs/bug388.go:17:19: error: non-name on left side of ‘:=’
fixedbugs/bug388.go:22:9: error: non-name on left side of ‘:=’
fixedbugs/bug388.go:27:10: error: expected type
fixedbugs/bug388.go:32:9: error: expected type
fixedbugs/bug388.go:23:14: error: reference to field ‘i’ in object which has no fields or methods
fixedbugs/bug388.go:18:18: error: invalid use of type

fixedbugs/bug389.go:12:5: error: incompatible type in initialization (different parameter types)

fixedbugs/bug390.go:15:24: error: expected integer, floating, or complex type

fixedbugs/bug394.go:10:1: error: expected declaration

fixedbugs/bug397.go:12:2: error: incompatible type for element 2 key in map construction

switch3.go:18:2: error: incompatible types in binary expression
switch3.go:22:2: error: incompatible types in binary expression
switch3.go:28:2: error: map can only be compared to nil
switch3.go:35:2: error: slice can only be compared to nil
switch3.go:42:2: error: func can only be compared to nil

syntax/else.go:11:9: error: expected ‘if’ or ‘{’

typeswitch2.go:15:2: error: duplicate type in switch
typeswitch2.go:19:2: error: duplicate type in switch
typeswitch2.go:26:2: error: duplicate type in switch
typeswitch2.go:40:9: error: ‘t’ declared and not used

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5573073
2012-01-26 23:06:47 -08:00
Ian Lance Taylor 09977734cd test: gccgo and gc print the error on different lines.
This introduces GC_ERROR to mark an error only issued by the
gc compiler.  GCCGO_ERROR already exists to mark errors only
issued by the gccgo compiler.  Obviously these should be used
sparingly.

bug195.go:9: error: interface contains embedded non-interface
bug195.go:12: error: interface contains embedded non-interface
bug195.go:15: error: interface contains embedded non-interface
bug195.go:18: error: invalid recursive interface
bug195.go:22: error: invalid recursive interface

R=rsc
CC=golang-dev
https://golang.org/cl/2040043
2010-08-31 14:12:23 -07:00
Russ Cox 7b5789b584 gc: undo attempt at fixing recursive interface embedding
Fixes #582.

Update #287
Status: Accepted
Bug fix was too intrusive; undo and reopen issue.

R=ken2
CC=golang-dev
https://golang.org/cl/209044
2010-02-16 17:44:15 -08:00
Russ Cox 44898c7b76 gc: bug250, bug251 - recursive interface types
Fixes #287.

R=ken2
CC=golang-dev
https://golang.org/cl/199057
2010-02-01 23:58:49 -08:00
Russ Cox 28b655ea07 more interface embedding tests
6g's error for I4 is not quite accurate
(it calls I4 a non-interface) but also
not a crash or infinite loop.

R=iant
DELTA=15  (15 added, 0 deleted, 0 changed)
OCL=33701
CL=33709
2009-08-21 21:30:24 -07:00
Russ Cox 59e2e54eab fix bug195
R=ken
OCL=33700
CL=33700
2009-08-21 18:07:11 -07:00
Renamed from test/bugs/bug195.go (Browse further)