go/types: various comment improvments (cleanup)

Change-Id: I0763f7ef202f9dec11abd4f204ab950b86e0272c
This commit is contained in:
Robert Griesemer 2020-01-07 21:21:19 -08:00
parent 45dd45561e
commit c49fde5b11
4 changed files with 17 additions and 8 deletions

View File

@ -5,7 +5,6 @@ so we have a better track record. I only switched to this file in Nov 2019, henc
TODO
- type assertions on/against parameterized types
- no need for error messages where a _ type parameter cannot be inferred (_ cannot be used)
- use Underlying() to return a type parameter's bound? investigate!
- if type parameters are repeated in recursive instantiation, they must be the same order (not yet checked)
- debug (and error msg) printing of generic instantiated types needs some work
@ -13,12 +12,17 @@ TODO
- use []*TypeParam for tparams in subst? (unclear)
----------------------------------------------------------------------------------------------------
OPEN ISSUES
KNOWN ISSUES
- instantiating a parameterized function type w/o value or result parameters may have unexpected side-effects
(we don't make a copy of the signature in some cases) - investigate
- using a contract and enumerating type arguments currently leads to an error (e.g. func f(type T C(T)) (x T) ... )
- using a contract and providing type arguments currently leads to an error (e.g. func f(type T C(T)) (x T) ... )
- leaving away unused receiver type parameters leads to an error; e.g.: "type S(type T) struct{}; func (S) _()"
- using _ for an unused receiver type parameter leads to an error and crash; e.g.: "type T(type P) int; func (_ T(_)) m()"
----------------------------------------------------------------------------------------------------
OPEN QUESTIONS
- confirm that it's ok to use inference in missingMethod to compare parameterized methods
- now that we allow parenthesized embedded interfaces, should we allow parenthesized embedded fields?
(probably yes, for symmetry and consistency).

View File

@ -502,12 +502,13 @@ func (check *Checker) collectObjects() {
// cannot easily work around).
func (check *Checker) unpackRecv(rtyp ast.Expr, unpackParams bool) (ptr bool, rname *ast.Ident, tparams []*ast.Ident) {
L: // unpack receiver type
// This accepts invalid receivers such as ***T but we don't care.
// The validity of receiver expressions is checked elsewhere.
for {
switch t := rtyp.(type) {
case *ast.ParenExpr:
rtyp = t.X
case *ast.StarExpr:
// TODO(gri) this is incorrect - we shouldn't permit say ***T as a receiver here
rtyp = t.X
default:
break L

View File

@ -27,8 +27,11 @@ type II interface{
var _ I = II(nil)
*/
type T(type P) int
func (_ T(P)) m() int
func _() {
contract /* ERROR "inside function" */ C() {}
contract /* ERROR "inside function" */ C(T) {}
contract /* ERROR "inside function" */ C(T) { C(T); T m(); T int }
}
// var x T(int)
// _ = x.m()
}

View File

@ -176,6 +176,7 @@ func (check *Checker) funcType(sig *Signature, recvPar *ast.FieldList, ftyp *ast
// - a receiver type parameter is like any other type parameter, except that it is passed implicitly (via the receiver)
// - the receiver specification acts as local declaration for its type parameters (which may be blank _)
// - if the receiver type is parameterized but we don't need the parameters, we permit leaving them away
// (TODO(gri) this is not working because the code doesn't allow an uninstantiated parameterized recv type)
_, rname, rparams := check.unpackRecv(recvPar.List[0].Type, true)
if len(rparams) > 0 {
sig.rparams = check.declareTypeParams(nil, rparams, nil)