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
Original code by iant@. Slightly streamlined and fixed a bug in the
process (if there is a type error in the contract, we only must "use"
the type arguments if they exist in the first place).
Change-Id: Id404d2cd4fd081b9a8053e194bf643593093e397
Assertions/type switches that are guaranteed to fail on generic
types are not permitted (in contrast to regular type assertions
and type switches).
Change-Id: Iaa5b96f094585cb206fdadaa501445f96f26c166
Instead of rewriting the underlying AST for a receiver type in place,
explicitly pass the rewritten AST to Checker.collectParams.
Also, better comments in various places.
Change-Id: If64e80b2c6b4b57477a4a0bf87caaa2f4ea1bf21
For symmetry with embedding in structs and interfaces.
Fixed an incorrect error message print in the process.
Change-Id: I295685438a22971edc610e6c51cfefd286eaffba
To be able to distinguish between a named field with a parenthesized
type `foo (T)` and an embedded parameterized type `foo(T)` in structs
we permit the use of parentheses in embedded types. For instance, the
latter example will need to be written as `(foo(T))`.
The parser now accepts any parenthesized embedded type liberally
and assumes that type-checking makes sure only permissible types
are accepted. As a result, parsing of field declarations is now
massively simpler. Also, removed an unused function.
The type-checker now complains about invalid embedded types (as
opposed to an invalid AST); it also now accepts embedded parameterized
types.
Change-Id: Ib8c6cbea9a0b739f66ba266fb5f8b71f91b7b64e
Instead of passing around a type parameter list and type arguments,
create a substitution map from them and use that map instead.
Change-Id: Ia4a041d95bfaa98888c9c06812d33b3d2a79227d
Make sure that a generic signature is not generic anymore
after instantiation. Update various related comments.
Change-Id: I2ac81037e570dc3a96c138b85529f3d86030776a
Simplifies Checker.typeDecl. Also, methods can only be added to
top-level types; no need to try to collect them for local types.
Change-Id: I05b926df7ffa70c32c1dd5faed3c68617be8f270
Make sure receiver type and actual receiver argument
match in "pointer-ness" before attempting to infer
any receiver type parameters.
Change-Id: Ie28004ce42ecef46e348424140b8d0c65e37cdaa
Added an accessor function to go/types:
// TParams returns the type parameters of the named type t, or nil.
func (t *Named) TParams() []*TypeName { return t.tparams }
Change-Id: Ife2322c73dd6eaecaed42655a57a37541661d1ed
Just store the error in the translator struct, rather than always
checking for an error and returning it up the stack.
Change-Id: I38ea2a282f61457eea123f852d9daf9337bcf9b8
Good enough to run this program:
package main
import "fmt"
func Print(type T)(s []T) {
for _, v := range s {
fmt.Println(v)
}
}
func PrintInts(s []int) {
Print(int)(s)
}
func main() {
PrintInts([]int{1, 2})
}
Change-Id: I5ac205138085a63e7075b01ca2779b7eb71f9682
Adds a new command go2go, invocable after installation as "go tool go2go".
The go2go command supports build, test, run, and translate subcommands.
These will translate .go2 files to .go files.
No actual translation is done yet; the files are simply rewritten.
So this is a framework that works if the .go2 files are pure Go 1 code.
Change-Id: I8183fd276c4c87577c428794fb87e8dde1fa398d
TODO
- some channel errors are not reported for generic variables
- error messages should be better
Change-Id: Ie388d6811b605645ea092481eee3a850c7ceb77b
Contract instantiation (= contracts with explicit type
arguments) should work now but has some implementation
restrictions:
- The type arguments provided to a contract must be
type parameters from the type parameter list using
the contract or the type parameter list of the en-
closing contract (in case of contract embedding).
- Each type argument may be used at most once per
contract expression.
Change-Id: Ia9f9d81e95d84f11ff3821b9f17b74eadab201f8