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
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