aboutsummaryrefslogtreecommitdiff
path: root/src/go
AgeCommit message (Collapse)Author
2022-01-12go/types, types2: fix tracing output for type and expr listsRobert Griesemer
- support printing of expression and type lists in sprintf - simplified some code in go/types/exprstring.go - fixed a typo in syntax package Change-Id: Ic4bc154200aad95958d5bc2904a9ea17cf518388 Reviewed-on: https://go-review.googlesource.com/c/go/+/377974 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2022-01-12go/types, types2: prevent unification from recursing endlesslyRobert Griesemer
This is a stop gap solution to avoid panics due to stack overflow during type unification. While this doesn't address the underlying issues (for which we are still investigating the correct approach), it prevents a panic during compilation and reports a (possibly not quite correct) error message. If the programs are correct in the first place, manually providing the desired type arguments is a viable work-around, resulting in code that will continue to work even when the issues here are fixed satisfactorily. For #48619. For #48656. Change-Id: I13bb14552b38b4170b5a1b820e3172d88ff656ec Reviewed-on: https://go-review.googlesource.com/c/go/+/377954 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2022-01-12go/types, types2: make function type inference argument-order independentRobert Griesemer
If we have more than 2 arguments, we may have arguments with named and unnamed types. If that is the case, permutate params and args such that the arguments with named types are first in the list. This doesn't affect type inference if all types are taken as is. But when we have inexact unification enabled (as is the case for function type inference), when a named type is unified with an unnamed type, unification proceeds with the underlying type of the named type because otherwise unification would fail right away. This leads to an asymmetry in type inference: in cases where arguments of named and unnamed types are passed to parameters with identical type, different types (named vs underlying) may be inferred depending on the order of the arguments. By ensuring that named types are seen first, order dependence is avoided and unification succeeds where it can. This CL implements the respectice code but keeps it disabled for now, pending decision whether we want to address this issue in the first place. For #43056. Change-Id: Ibe3b08ec2afe90a24a8c30cd1875d504bcc2ef39 Reviewed-on: https://go-review.googlesource.com/c/go/+/377894 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2022-01-12go/ast: mention that FieldLists can now be enclosed by bracketsRobert Findley
Type parameter lists are stored using ast.FieldLists. Update the documentation to reflect that the enclosing delimiter may be a bracket. Change-Id: Id103e7b38975e94a1b521f75695edc10408ad3dd Reviewed-on: https://go-review.googlesource.com/c/go/+/378014 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-01-12go/types, types2: do not run CTI before FTIRobert Griesemer
Until now, CTI (constraint type inference) was run before FTI (function type inference). This lead to situations where CTI infered a type that is missing necessary methods even though a function argument of correct type was given. This can happen when constraint type inference produces a inferred type that is the structural type of multiple types, which then is an underlying type, possibly without methods. This CL removes the initial CTI step; it is only applied after FTI with type arguments is run, and again after FTI with untyped arguments is run. Various comments are adjusted to reflect the new reality. Fixes #50426. Change-Id: I700ae6e762d7aa00d742943a2880f1a1db33c2b8 Reviewed-on: https://go-review.googlesource.com/c/go/+/377594 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2022-01-12cmd/compile/types2, go/types: add position for "have" in failed interface ↵Emmanuel T Odeke
satisfaction With this change, we shall now see: *myS does not implement S (wrong type for DoSomething method) have DoSomething() (string, error) at ./main.go:9:14 want DoSomething() (int, error) instead of previously: *myS does not implement S (wrong type for DoSomething method) have DoSomething() (string, error) want DoSomething() (int, error) Fixes #42841 Fixes #45813 Change-Id: I66990929e39b0d36f2e91da0d92f60586a9b84e5 Reviewed-on: https://go-review.googlesource.com/c/go/+/373634 Trust: Robert Findley <rfindley@google.com> Trust: Emmanuel Odeke <emmanuel@orijtech.com> Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2022-01-11go/types, types2: mention type decl scopes in Info.Scopes documentationRobert Findley
We now may have a scope associated with a type declaration, so need to update our API documentation accordingly. Change-Id: Ic66dc3b7cd1969b25fb7c4bee986d76ab3544042 Reviewed-on: https://go-review.googlesource.com/c/go/+/377655 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-01-10go/types, types2: refer to type parameter if so for interface pointer errorsRobert Griesemer
Follow-up on comment in CL 376914. Also: - add missing check != nil test in assignableTo - use check.sprintf rather than fmt.Sprintf in missingMethodReason For #48312. Change-Id: Ie209b4101a7f2c279e42a59987d0068079c8b69f Reviewed-on: https://go-review.googlesource.com/c/go/+/377375 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2022-01-10go/types, types2: better error message for type parameter field accessRobert Griesemer
Fixes #50516. Also call DefPredeclaredTestFuncs in TestFixedbugs so it can be run independently again. Change-Id: I78d4cc11790b1543a2545a7ab297a223b3d5e3c8 Reviewed-on: https://go-review.googlesource.com/c/go/+/376954 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2022-01-10go/types, types2: better error message when using *interface instead of ↵Robert Griesemer
interface - detect *interface case and report specific error - replaced switch with sequence of if's for more clarity - fixed isInterfacePtr: it applies to all interfaces, incl. type parameters - reviewed/fixed all uses of isInterfacePtr - adjusted error messages to be consistently of the format "type %s is pointer to interface, not interface" Fixes #48312. Change-Id: Ic3c8cfcf93ad57ecdb60f6a727cce9e1aa4afb5d Reviewed-on: https://go-review.googlesource.com/c/go/+/376914 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2022-01-09go/types, types2: better error message for invalid == on type parametersRobert Griesemer
Fixes #48712. Change-Id: I6f214cdfdd1815493f2a04828e8f0097f1d8c124 Reviewed-on: https://go-review.googlesource.com/c/go/+/372734 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2022-01-07cmd/compile: accept string|[]byte-constrained 2nd argument in appendRobert Griesemer
Similarly to what we do for the built-in function `copy`, where we allow a string as 2nd argument to append, also permit a type parameter constrained by string|[]byte. While at it, change date in the manual.go2 test files so that we don't need to constantly correct it when copying a test case from that file into a proper test file. Fixes #50281. Change-Id: I23fed66736aa07bb3c481fe97313e828425ac448 Reviewed-on: https://go-review.googlesource.com/c/go/+/376214 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2022-01-07go/types, types2: disallow multiple blank type parametersRobert Griesemer
Work-around for #50481: report an error for multiple blank type parameters. It's always possible to use non-blank names in those cases. We expect to lift this restriction for 1.19. For #50481. Change-Id: Ifdd2d91340aac1da3387f7d80d46e44f5997c2a8 Reviewed-on: https://go-review.googlesource.com/c/go/+/376058 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> Trust: Dan Scales <danscales@google.com> Reviewed-by: Dan Scales <danscales@google.com> Reviewed-by: Robert Findley <rfindley@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-01-06go/types, types2: implement field access for struct structural constraintsRobert Griesemer
This change implements field the access p.f where the type of p is a type parameter with a structural constraint that is a struct with a field f. This is only the fix for the type checker. The compiler will need a separate CL. This makes the behavior consistent with the fact that we can write struct composite literals for type parameters with a struct structural type. For #50417. For #50233. Change-Id: I87d07e016f97cbf19c45cde19165eae3ec0bad2b Reviewed-on: https://go-review.googlesource.com/c/go/+/375795 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2022-01-06go/types, types2: remove unused code in lookupFieldOrMethodRobert Griesemer
The underlying type of a type parameter is an interface, so we don't need a special case for type parameters anymore. Simply share the (identical) code for interfaces. Adjust code in types.NewMethodSet accordingly. No functional difference. Preparation for fix of issues below. For #50233. For #50417. Change-Id: Ib2deadd12f89e6918dec224b4ce35583001c3101 Reviewed-on: https://go-review.googlesource.com/c/go/+/375514 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2022-01-06go/types, types2: ensure that signature type bounds are interfacesRobert Griesemer
Do this by running verification for instantiated signatures later, after the delayed type parameter set-up had a chance to wrap type bounds in implicit interfaces where needed. Fixes #50450 Change-Id: If3ff7dc0be6af14af854830bfddb81112ac575cb Reviewed-on: https://go-review.googlesource.com/c/go/+/375737 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2022-01-06go/types, types2: eagerly check that constraints are not type paramsRobert Findley
As a result of the change to the underlying of a type parameter to be its constraint interface, we had couple inaccuracies that combined to cause an infinite recursion when type checking the invalid type parameter list [A A]. - We deferred tpar.iface() using check.later twice: once in newTypeParam, and then again at the end of collectTypeParams. - We deferred the check that type parameter constraints are not type parameters, even though this is unnecessary: the constraint type is known. With these inaccuracies, tpar.iface() was executing before our guard against using type parameters as constraints, causing an infinite recursion through under(). Fix this by eagerly checking whether the constraint is a type parameter, and marking it invalid if so. Also remove the unnecessary calls to tpar.iface() at the end of collectTypeParams, as this will already have been scheduled by newTypeParam. Fixes #50321 Change-Id: I4eecbecf21656615867cb94be65b520e9e795bd1 Reviewed-on: https://go-review.googlesource.com/c/go/+/374294 Reviewed-by: Robert Griesemer <gri@golang.org> Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-01-03go/doc: handle generic receiver stringsJonathan Amsterdam
A receiver expression for a type with parameters may be an IndexExpr or IndexListExpr in addition to an Ident or StarExpr. Add cases to recvString to account for the new types. Add tests that compare the fields of Func, and the fields of Type that hold Funcs. These fields weren't previously tested. Change-Id: Ia2cef51c85113422e0c5745c77dddcd53507ee51 Reviewed-on: https://go-review.googlesource.com/c/go/+/375095 Trust: Jonathan Amsterdam <jba@google.com> Run-TryBot: Jonathan Amsterdam <jba@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-01-03go/doc: use subtestsJonathan Amsterdam
Change the Test function to use sub-tests for each doc mode and package. This will allow more fine-grained test execution. Change-Id: Ie3dda5791bda2781a60776886dd39fd18e670e24 Reviewed-on: https://go-review.googlesource.com/c/go/+/375094 Trust: Jonathan Amsterdam <jba@google.com> Run-TryBot: Jonathan Amsterdam <jba@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-12-20all: fix spelling errors found by misspellDan Kortschak
Change-Id: Icedd0c3d49259d5aee249ecb33374e9b78e0c275 Reviewed-on: https://go-review.googlesource.com/c/go/+/373376 Reviewed-by: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-12-20go/types: better error message when using comparable in unionRobert Griesemer
This is a port of CL 372674 from types2 to go/types with minor adjustments for error handling. For #49602. Change-Id: I726081325a2ff2d5690d11ddc8a830bbcbd8ab33 Reviewed-on: https://go-review.googlesource.com/c/go/+/372954 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-12-20go/types, types2: delay "does not satisfy comparable" error until neededRobert Griesemer
Fixes #49112. Change-Id: I8effbca7bcbb257b18fd4d3d1914fd10d4afaaae Reviewed-on: https://go-review.googlesource.com/c/go/+/372594 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-12-17go/types, types2: use compiler error message for undefined operatorsRobert Griesemer
For #48712. Change-Id: I1596fe8688f093e0e92cf5b8d5501aac8631324e Reviewed-on: https://go-review.googlesource.com/c/go/+/372894 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-12-15cmd/compile/internal/types2: record types for union subexpressionsRobert Griesemer
This is a port of CL 371757 from go/types to types2, with minor adjustments for different error handling and AST. It also names the added API test cases more consistently. The same renaming was applied to the respective go/types file. Updates #50093 Change-Id: Iaa132106a197a207f831525432e62e9d452b17c9 Reviewed-on: https://go-review.googlesource.com/c/go/+/372475 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-12-15all: fix typo in commentichxxx
Remove duplicate 'the' Change-Id: I3ed81c8d9c488662387e45580a3bcd462448ba44 GitHub-Last-Rev: 86443993b9b58c6fce4e09e283604c32ccc44cec GitHub-Pull-Request: golang/go#50017 Reviewed-on: https://go-review.googlesource.com/c/go/+/372394 Reviewed-by: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-12-14go/types: record types for union subexpressionsRobert Findley
Prior to unions, unary and binary expressions always had a recorded type. Preserve this by recording a type for all unary and binary expressions encountered while parsing a union type. Updates #50093 Change-Id: I5ba20f37854760596350d91ea325dc98e67e115a Reviewed-on: https://go-review.googlesource.com/c/go/+/371757 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-12-14go/types: externalize union type setsRobert Findley
Move calculated type sets for unions into a map, rather than storing them on the Union type. Type sets for unions only matter during calculation of interface type sets, and to a lesser extent inside of Identical. The latter should not be encountered during type checking, as Identical uses the precomputed interface type set when comparing interfaces, and unions do not arise outside of interface types. Removing the tset field from Union potentially frees up memory, and eliminates a source of races via calls to NewUnion and Identical. It also sets the stage for recording Unions for every subexpression of union terms, which preserves an existing invariant that BinaryExprs and UnaryExprs should have a recorded type. Updates #50093 Change-Id: I5956fa59be6b0907c3a71faeba9fa5dd8aae0d65 Reviewed-on: https://go-review.googlesource.com/c/go/+/371756 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-12-14go/types, types2: record (top-level) union typesRobert Griesemer
Fixes #50093. Change-Id: Ibebeda542d2a81c979670f9098c4a6d2c3e73abb Reviewed-on: https://go-review.googlesource.com/c/go/+/371514 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-12-13all: gofmt -w -r 'interface{} -> any' srcRuss Cox
And then revert the bootstrap cmd directories and certain testdata. And adjust tests as needed. Not reverting the changes in std that are bootstrapped, because some of those changes would appear in API docs, and we want to use any consistently. Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories when preparing the bootstrap copy. A few files changed as a result of running gofmt -w not because of interface{} -> any but because they hadn't been updated for the new //go:build lines. Fixes #49884. Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09 Reviewed-on: https://go-review.googlesource.com/c/go/+/368254 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-12-10go/types: remove TODO that is no longer relevantHossein Zolfi
Change-Id: Ie897b7b9c0a61c837245642c608129108e28423e Reviewed-on: https://go-review.googlesource.com/c/go/+/370582 Reviewed-by: Robert Findley <rfindley@google.com> Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> Trust: Nooras Saba‎ <saba@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-12-09cmd/compile: fix type error reported on the wrong lineJason7602
The 'Does not match' type error shoud be reported where the function is called, not where the function is declared. And fix the todo by gri of issue45985 Fixes #45985 Fixes #49800 Change-Id: I15aac44dd44f2a57c485a1c273fcd79db912c389 Reviewed-on: https://go-review.googlesource.com/c/go/+/362634 Reviewed-by: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-12-08go/types: sort to reduce computational complexity of initOrderRobert Findley
Our calculation of initOrder builds the dependency graph and then removes function nodes approximately at random. While profiling, I noticed that this latter step introduces a superlinear algorithm into our type checking pass, which can dominate type checking for large packages such as runtime. It is hard to analyze this rigorously, but to give an idea of how such a non-linearity could arise, suppose the following assumptions hold: - Every function makes D calls at random to other functions in the package, for some fixed constant D. - The number of functions is proportional to N, the size of the package. Under these simplified assumptions, the cost of removing an arbitrary function F is P*D, where P is the expected number of functions calling F. P has a Poisson distribution with mean D. Now consider the fact that when removing a function F in position i, we recursively pay the cost of copying F's predecessors and successors for each node in the remaining unremoved subgraph of functions containing F. With our assumptions, the size of this subgraph is proportional to (N-i), the number of remaining functions to remove. Therefore, the total cost of removing functions is proportional to P*D*Σᴺ(N-i) which is proportional to N². However, if we remove functions in ascending order of cost, we can partition by the number of predecessors, and the total cost of removing functions is proportional to N*D*Σ(PMF(X)) where PMF is the probability mass function of P. In other words cost is proportional to N. Assuming the above analysis is correct, it is still the case that the initial assumptions are naive. Many large packages are more accurately characterized as combinations of many smaller packages. Nevertheless, it is intuitively clear that removing expensive nodes last should be cheaper. Therefore, we sort by cost first before removing nodes in dependencyGraph. We also move deletes to the outer loop, to avoid redundant deletes. By inspection, this avoids a bug where n may not have been removed from its successors if n had no predecessors. name old time/op new time/op delta Check/runtime/funcbodies/noinfo-8 568ms ±25% 82ms ± 1% -85.53% (p=0.000 n=8+10) name old lines/s new lines/s delta Check/runtime/funcbodies/noinfo-8 93.1k ±56% 705.1k ± 1% +657.63% (p=0.000 n=10+10) Updates #49856 Change-Id: Id2e70d67401af19205e1e0b9947baa16dd6506f0 Reviewed-on: https://go-review.googlesource.com/c/go/+/369434 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-12-06go/types, types2: unexport NewTypeListRobert Findley
NewTypeList was not part of the go/types API proposal, and was left in by accident. It also shouldn't be necessary, so remove it. Updates #47916 Change-Id: I4db3ccf036ccfb708ecf2c176ea4921fe68089a4 Reviewed-on: https://go-review.googlesource.com/c/go/+/369475 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2021-12-03test: re-enable a bunch of tests with types2Dan Scales
Enable a bunch of types2-related error tests to run successfully, so they no longer have to be disabled in run.go. - directive.go: split it into directive.go and directive2.go, since the possible errors are now split across the parser and noder2, so they can't all be reported in one file. - linkname2.go: similarly, split it into linkname2.go and linkname3.go for the same reason. - issue16428.go, issue17645.go, issue47201.dir/bo.go: handle slightly different wording by types2 - issue5609.go: handle slight different error (array length must be integer vs. array bound too large). - float_lit3.go: handle slightly different wording (overflows float vs cannot convert to float) I purposely didn't try to fix tests yet where there are extra or missing errors on different lines, since that is not easy to make work for both -G=3 and -G=0. In a later change, will flip to make the types2 version match correctly, vs. the -G=0 version. Change-Id: I6079ff258e3b90146335b9995764e3b1b56cda59 Reviewed-on: https://go-review.googlesource.com/c/go/+/368455 Trust: Dan Scales <danscales@google.com> Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2021-12-02cmd/compile: report channel size errors correctly for -G=3Dan Scales
First, we need to set base.Pos in varDecl() and typeDecl(), so it will be correct if we need to report type size errors while converting types. Changed error calls in types/sizes.go to use Errorf, not ErrorfAt, since we want to use base.Pos (which will set from t.Pos(), if that is available). Second, we need to add an extra call CalcSize(t1.Elem()) in the TCHANARGS case of CalcSize(). We can use CalcSize() rather than CheckSize(), since we know the top-level recursive type will have been calculated by the time we process the fake TCHANARGS type. In -G=0 mode, the size of the channel element has often been calculated because of some other processing (but not in the case of #49767). But in -G=3 mode, we just calculate sizes during the single noder2 pass, so we are more likely to have not gotten to calculating the size of the element yet, depending on the order of processing of the deferredTypeStack. Fixes the tests fixedbugs/issue{42058a,42058b}.go that were disabled for -G=3 mode. Had to add exceptions in stdlib_test.go for go/types and types2, because the types2 typechecker does not know about type size limits. Fixes #49814 Fixes #49771 Updates #49767 Change-Id: I77d058e8ceff68a58c4c386a8cf46799c54b04c3 Reviewed-on: https://go-review.googlesource.com/c/go/+/367955 Trust: Dan Scales <danscales@google.com> Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2021-12-01gcimporters: allow reusing empty interfaces on the RHS of type declsRobert Findley
We guard against caching or reusing interfaces on the RHS of a type declaration, because for such interfaces the base type is used as the interface method receiver type. However, we don't need to do this for empty interfaces. By refining our guard, we can allow importing the predeclared 'any' type on the RHS of a type declaration. Update tests to add more coverage for importing generic export data. Some accomodation had to be made for the unified builder, which does not yet fully support generics in export data. Fixes #49888 Change-Id: I51f329de464fc7309f95991b839ab55868c2924f Reviewed-on: https://go-review.googlesource.com/c/go/+/367851 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2021-11-30cmd/compile: change iexportVersionGeneric to 2Dan Scales
Don't expect/allow generics-related info in iexportVersion 1, now that we increased the export version to 2. Fixes #49853 Change-Id: I9bacee7f8e7cb9bb3b02a00084fad77edd220121 Reviewed-on: https://go-review.googlesource.com/c/go/+/367634 Trust: Dan Scales <danscales@google.com> Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Heschi Kreinick <heschi@google.com>
2021-11-29go/types, types2: handle case of no specific target types in conversionRobert Findley
Avoid a panic by handling the case of no specific target type in a type parameter to type parameter conversions. Fixes #49864 Change-Id: I117dd80cc9d47c8c1e168f1caf0f281726270c84 Reviewed-on: https://go-review.googlesource.com/c/go/+/367616 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
2021-11-29go/types: ensure that constructed type parameters are immutableRobert Findley
TypeParam.iface may mutate TypeParam.bound in the event that the type parameter bound is not an interface. Ensure that iface() is called before the type-checking pass returns, and before NewTypeParam or TypeParam.SetConstraint exits. Fixes #49788 Change-Id: I72279acf5f0223161671c04887bc2c3df4158927 Reviewed-on: https://go-review.googlesource.com/c/go/+/367614 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2021-11-29go/types: consider structural restrictions in ImplementsRobert Findley
Fixes #49786 Change-Id: I4559d013399deda48bcb97aef3427ecf87a3ef26 Reviewed-on: https://go-review.googlesource.com/c/go/+/367515 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2021-11-29go/types: better error message for missing ~ in constraintRobert Griesemer
This is a port of CL 366758 from types2 to go/types. For #49179. Change-Id: I7e1c6ffb392d5c535cf901004b7acbe8c3be9b0f Reviewed-on: https://go-review.googlesource.com/c/go/+/367199 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-11-29go/types: better error position for instantiation failureRobert Griesemer
This is a port of CL 366757 from types2 to go/types, adjusted for the different handling of index expressions in go/types. For #49179. Change-Id: Ic859eb09683134d055e28c8e0cb1f3814a87dc5c Reviewed-on: https://go-review.googlesource.com/c/go/+/367198 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-11-29go/types: produce empty type set for invalid ~TRobert Griesemer
This is a clean port of CL 366278 from types2 to go/types. For #49739. Change-Id: I2e2cb739c02fcc07e012499c7b65b13b057875ea Reviewed-on: https://go-review.googlesource.com/c/go/+/367197 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-11-29go/types: report types for mismatched call and return statementsRobert Griesemer
This is a port of CL 364874 from types2 to go/types with various adjustments: - the error position for "not enough arguments" in calls is the closing ) rather than the position of the last provided argument - the ERROR comments in tests are positioned accordingly - the reg. expression for matching error strings accepts newlines for the . pattern (added s flag) For #48834. For #48835. Change-Id: I64362ecf605bcf9d89b8dc121432e0131bd5da1b Reviewed-on: https://go-review.googlesource.com/c/go/+/367196 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-11-29go/types: restore original assignment error messagesRobert Griesemer
This is the missing portion of the port of CL 351669 from types2 to go/types, now that we have a local flag to control for compiler error messages. Mostly a clean port but for adjustments to error reporting which requires error codes in go/types. Prerequisite for port of CL 364874. Change-Id: I5fc8c83003e4396351f42e9adb08f4ebc8a05653 Reviewed-on: https://go-review.googlesource.com/c/go/+/367195 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-11-24go/types: print "nil" rather than "untyped nil"Robert Griesemer
This is a port of CL 366276 from types2 to go/types with minor adjustments due to the slightly different handling of nil in go/types. It uses some more detailed error strings in stmt0.src; the same changes are made to the corresponding types2 file. For #48852. Change-Id: I2cdf258799bcbe2d12bbadaf67b8b4504b356bd0 Reviewed-on: https://go-review.googlesource.com/c/go/+/366277 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
2021-11-22cmd/go: allow a package that ends with _test having an internal test packageRyan Leung
Fixes #45477 Change-Id: I2f1ed281515ec40d31fd07ce9f4901777691bfa7 GitHub-Last-Rev: 7894d9400c95b8d84efe88f401fa75c3dd01921a GitHub-Pull-Request: golang/go#49673 Reviewed-on: https://go-review.googlesource.com/c/go/+/365534 Trust: Heschi Kreinick <heschi@google.com> Reviewed-by: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org>
2021-11-22go/types, types2: substitute for type parameters in signatures whenRobert Findley
comparing type identity Generic signatures should be considered identical modulo type parameter renaming. Update Identical to reflect this, by substituting type parameters. Fixes #49722 Change-Id: I33743768c72d8aa59c29bf72fcbabc5974f0b805 Reviewed-on: https://go-review.googlesource.com/c/go/+/366178 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
2021-11-22go/types,types2: use allInteger to check type for shifted operandzhouguangyuan
Fixes: #49705 Change-Id: I35a1c5f29b57f3facc5e89d33a8dec88e0ff4afa Reviewed-on: https://go-review.googlesource.com/c/go/+/365895 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> Trust: Emmanuel Odeke <emmanuel@orijtech.com>
2021-11-18go/types: add test for imported constraints pre-1.18Robert Findley
This is a port of CL 363834 from types2 to go/types. Change-Id: I32583ead4bce626e0761f4c327678050404a15c9 Reviewed-on: https://go-review.googlesource.com/c/go/+/364937 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>