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
The typestring for embedded fields in structs was changed
by 8d30bd752d4 (type checking of function type parameters)
but this test was not updated.
Change-Id: I0d9438e3000939de09aa298c33ad1e9604a59fe8
Interface.is already takes care of iterating through all types of
a generic type bound; use it instead of writing custom loops each
time.
Change-Id: Ie0f91b27e5a7b65ea85a8c3847a954db1e9f24fe
This enables the distinction between a method M(int) and an
embedded instantiated (parameterized) interface (M(int)).
Change-Id: I150d1b1cd53a2b14ddc0ad6336d84078fcb41ad6
This simplifies the use of missingMethod again but moving the lazy
instantiation of methods into missingMethod. Method comparison now
also takes method type paramaters into account.
This change enables the first examples of parameterized methods
to type-check.
Change-Id: I4c629fb7b1f8959184c6ce5196365893d11b197d
Fixes bug with generic min being accepted even though the contract
or interface bound doesn't enumerate any types (or is missing).
Change-Id: Icdfc62fbd2b73ece397d5b5f1ebe27e52ed9b32f
This step further consolidates all parameter types (except for the
receiver) in an ast.FuncType which now matches more closely the
representation of a types.Signature. As a result, fewer parameters
need to passed around because we can just use an *ast.FuncType or
a *types.Signature instead.
As an immediate (and implicit) consequence, parameterized interface
methods now type-check. (But we cannot yet "implement" them with a
matching concrete type.)
Change-Id: I2ea24694ade9838488625ffec48d5e98070d1006
This is a generalization of type parameters to methods.
Being able to type-check them (even if we don't have an
idea how to actually implement such methods) is likely
going to inform the structure the type-checker: If the
code is organized correctly, the generalization should
mostly just work (and consist of the elimination of
extra checks).
So far, this first step only exposed some minor scoping
issues (where does the scope of type parameters start).
Change-Id: I8658ea8d1876a0ce9c62c0e9a7e943301e9cc19d
This follows the approach used for methods, but there is no error
reporting yet if a type is (explicitly) declared multiple times in
an interface.
Change-Id: I52428174ae278577a7c538b0817c6fb7af1c369e
Type parameters are now collected as part of signature type
checking, as they are part of the type not the object. This
opens the door to more uniform handling of type parameters,
also for concrete methods and interface methods (future use).
Cleaned up confusion between Signature.mtparams and tparams:
tparams are explicitly declared function type parameters.
mtparams is gone and replaced with rparams which are the
receiver type parameters used in the function.
Various related cleanups.
Change-Id: Id8422b57cc8fbc18ffdca12a69d890aef83c3f80
A signature that's instantiated but doesn't have any incoming
or result (value) parameters doesn't get a copy automatically.
This leads to bugs because the instantiated signature doesn't
lose its type parameters when it should.
Make a copy outside for now, this fixes some (but not all cases)
and added test cases.
Also, factored out printing of type parameters in type printing.
Change-Id: I0ec3a4226c7473cddfb16704a2218992dd411593
This change completes the prior change by adjusting the go/types
implementation accordingly. As a consequence, contracts may now
not occur in type context anymore and errors are reported if they
do.
With this change, all tests pass again.
Change-Id: Id984b3d24b7cb6ff2fceb74fd3c33fd0af91fdce
Progress snapshot.
This change makes a contract declaration a proper declaration (as it is
envisioned in the design draft). Specifically, contracts cannot be used
in type position anymore, and a contract declaration is not treated as
a type declaration with the type being a contract.
The change has not been pushed through go/types yet; this change will
temporarily brake go/types.
Change-Id: Ia4034caebab07dac449a02cdd362d6ce5d61c4a3