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
Cases such as
func f(type T)(x T) {
f(x)
}
can now be type-checked. For more examples see examples/functions.go2
in the go/types directory.
Change-Id: Id661c84f086cc8ee45ec372ac4af543e68bebe8a
Contract embedding is reduced to interface embedding. When embedding
interfaces:
1) use the correct interface to embed; and
2) don't leave type bounds residue on the incoming type arguments
of the embedded interface/contract as those are also the type
parameters of the embedding (outer) interface/contract.
Also:
- For now, print "any" instead of "interface{}" (empty interface)
when printing type parameter lists to reduce clutter. Eventually
we should not print anything for empty interface bounds, but we
first must also group type parameters with the same type bounds.
- Print the type parameter subscript in type parameter lists to
make it clearer which type parameter we are referring to.
Change-Id: Ic83516096387d0f512c4c76a8a8fe849d51e033a
The comparable contract defines a magic method "==" which
enables comparisons with == and != . Comparable types
automagically implement this method.
TODO: If a type is not comparable but a comparable type is
expected, the error message can be confusing (missing ==
method).
Change-Id: Ie0d89b87c36d83549f7d869c18dd9786151adbae
More precisely, de-parameterize the corresponding interfaces when
embedding them in the corresponding type bounds (interfaces) for
the embedding contract. This prevents the embedded (and already
instantiated) interfaces from being instantiated again when the
outer interface is instantiated and avoids breaking an assertion.
See also the test case in testdata/issues.go2 for more details.
Change-Id: I70c9354849eda0c8a36905d0b80f4d3031542f30
We can now translate code that use type inference when calling generic
functions. A couple of test cases were adjusted to use it.
Change-Id: I53c2f3dd8f9fcdb44b4a8f592acee1a19ff46f22
In api.go, introduce a new type `Inferred` which collects type arguments
and signature in one place and which can be extended if need be.
Change-Id: I014dd52641843e85ad408fdaa07eda121cf1c41c