If a type or type parameter does not satisfy a contract because the
type or type constraint is not found in the list of type constraints,
change
T does not satisfy C(T) (T type constraint int not found in interface{type ...})
to
T does not satisfy C(T) (T type constraint int not found in [type ...])
Also, before this change, if the contract had any required methods,
those were also listed; now we just list the type constraints.
If a defined type does not satisfy a contract because the underlying
type is not found in the list of type constraints, change
MyUint does not satisfy C(T) (MyUint not found in interface{type ...})
to
MyUint does not satisfy C(T) (uint not found in [type ...])
That is, when describing the type that is not found, use the underlying type,
not the defined type.
Change-Id: I345836c44921e2e13e7f02041839b5eb4df75c45
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/718718
Reviewed-by: Robert Griesemer <gri@google.com>
If a type parameter that has no type constraints is trying to satisfy
a contract that does have type constraints, change
T does not satisfy C(T) (missing type int)
to
T does not satisfy C(T) (T has no type constraints)
If a type parameter that has type constraints is trying to satisfy a
contract that has type constraints, but the parameter has type
constraints that the contract does not permit, change
T does not satisfy C(T) (missing type int)
to
T does not satisfy C(T) (T type constraint int not found in interface{type ...}
Change-Id: I3bd4f59b0544b382399d9b9d891a509ce62f56c3
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/718426
Reviewed-by: Robert Griesemer <gri@google.com>
A type argument with an empty type list bound never satisfies
a type parameter with a non-empty type list bound.
Change-Id: Ic4206f74fd4625b4207baa28bdb0de0fc669b37e
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/717296
Reviewed-by: Robert Griesemer <gri@google.com>
slices.Equal only requires comparable, not Ordered.
Change-Id: I0150f1370e478aaa33bbd8788a1f9c9d33b85e06
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/716483
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Rewrite Interface.Empty to not be dependent on an interface being
complete. Be careful when printing invalid interfaces.
This fixes a couple of crashes when running tests with -v (trace)
mode enabled.
Change-Id: I4be416eac7e3fae83c08608ed74bf3987b2a7457
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/716089
Reviewed-by: Robert Griesemer <gri@google.com>
When a Go2 package imports a Go1 package, then if the Go1 package is
in the standard library use the default importer, but otherwise
parse the package ourselves by recursively calling go/types.
This supports a Go2 package importing a Go1 package that imports
a Go2 package.
Change-Id: I8906d8ea5b81e6239652c0e46de79b5c1b59cfcd
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/716063
Reviewed-by: Ian Lance Taylor <iant@google.com>
Otherwise we don't know the type of an instantiated type in an
instantiated function.
Change-Id: If7eb75dd920a3c9fc1b6992addcd3b91b6d425a9
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/715718
Reviewed-by: Ian Lance Taylor <iant@google.com>
We are only going to translate the .go2 files of an imported package,
so we don't need to copy anything else to the temporary directory.
This fixes the case of an imported package with a subdirectory,
which previously crashed trying to copy the directory.
Change-Id: I54cfb43ad2a3e23a4e0d7201d9e6e2ade02b7469
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/715029
Reviewed-by: Ian Lance Taylor <iant@google.com>
Also when looking for packages specified on the command line,
search GO2PATH before trying to invoke "go list".
Change-Id: I9704ef86fa46b877ee195a40843a034d014c2a3d
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/714998
Reviewed-by: Ian Lance Taylor <iant@google.com>
- leave type bounds away if empty (interface); don't write "any"
- boundle type parameters with the same type type bound
- simpler code for error message cleanup
Change-Id: I8c1b662479de185b2ebae47ed1d16482253dfe03
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/710076
Reviewed-by: Robert Griesemer <gri@google.com>
- store a *Named type in both caches
- update local cache also when we have a global cache hit
Change-Id: If4ab24a0c24d21f425a76dc51e4ec2ed495b26e4
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/710128
Reviewed-by: Robert Griesemer <gri@google.com>
Instead of creating a new instantiated type name "name<T1, T2...>"
keep the regular name for the corresponding type object since
these newly created types are never declared. This eliminates
the need to clean up the names (remove the <>'s) before they can
be used.
When printing a named type, simply decide what to print depending
on whether it is instantiated or not.
When looking up an instantiated type, simply create the instantiated
type name string for use in the (local and global) type caches.
Change-Id: I4b20d09ec64d8deefccdd338ffb2f78fdfd2101e
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/710062
Reviewed-by: Ian Lance Taylor <iant@google.com>
Per the draft design:
In a generic function body all method calls will be pointer method calls.
If necessary, the function body will insert temporary variables, not seen
by the user, in order to get an addressable variable to use to call the method.
When checking if a concrete type argument satisfies its type bound, assume
that concrete type is the type of an addressable value.
Change-Id: I9d40138755c38330448c010994b95a82f38e60e0
- added Error.Full and Error.FullError which provide the full error
message, possibly containing internal details
- Error.Msg and Error.Error provide a user-friendly error message
Change-Id: Id3044165331af71be31ef423cd2c9b8fe28accbd
Since the type bound of a type parameter is an interface, no method
is found if the receiver is a pointer to a type parameter (pointers
to interfaces have no methods).
Ignore the indirection in this case.
Change-Id: Ie2af78b4cfb2f70b5d4f1d2afc631716a10ff7d9
Pointer designations were not recognized nor supported.
Now we recognize them and report an error until type-checking
can handle them.
Change-Id: I0deed536aa03c06c3e9ec60a5c2e186e916b970f
Until now, types of type lists in interface types were collected in
a single expression list "Types". This made it not possible to gofmt
such interfaces while preserving the original layout of type lists.
This change represents types of type lists as part of an ast.FieldList.
The ast.InterfaceType.Methods field list now represents embedded interfaces,
methods, or type list types through ast.Fields. This preserves all position
information and thus permits accurate gofmt-ing.
The new representation is as follows: For an ast.Field f, if
- len(f.Names) == 0 : f.Type is an embedded interface
- f.Names[0].Name == "type": f.Type is a type of a type list
- otherwise : f represents a method
Since "type" is a keyword, a Go field name cannot be "type".
Fields of types of type lists that share the same "type" keyword
in the source share the same f.Names[0] identifier (named "type"),
and the position of that identifier is the position of the "type"
keyword in the source.
Related changes:
- Adjusted go/parser to build the new representation.
- Adjusted go/printer and implemented formatting of type lists.
(This is still not quite correct if there are comments, but
that is fine-tuning).
- Adjusted go/types to work with the new representation.
- Implemented SplitFieldList and MergeFieldList in go2go
translator to easily switch between old and new representation.
- Updated documentation.
Change-Id: I016e2ce5949bfe294509d703156c41d42cf7084e
Type unification now happens through the new unifier code.
We can revert the functionality of Checker.identical back
to its original purpose of type comparison. This change
should make identity comparison faster again.
Change-Id: I844515b5f20a890152a0a5436f04c553b3b722e5
- Implemented bidirectional unifier as a stand-alone mechanism
separate from Checker.identical0.
- Use it instead of Checker.identical0 where we need unification.
- Missing: Bidirection functionality not fully implemented because
we don't use it yet, but the basic outline is present.
Change-Id: I1666c9e4c9094eda749084bb69c700f1b5e879bb