From f81ad499396404daa711cd5629c2e5e259430db0 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 31 Mar 2020 22:26:03 -0700 Subject: [PATCH] go/types: report an error when seeing pointer designation in contracts Pointer designations were not recognized nor supported. Now we recognize them and report an error until type-checking can handle them. Change-Id: I0deed536aa03c06c3e9ec60a5c2e186e916b970f --- src/go/types/NOTES | 2 ++ src/go/types/contracts.go | 3 +++ src/go/types/testdata/tmp.go2 | 9 +++++++++ src/go/types/testdata/todos.go2 | 5 +++++ 4 files changed, 19 insertions(+) diff --git a/src/go/types/NOTES b/src/go/types/NOTES index 9f8ef96d10..b68c2cc650 100644 --- a/src/go/types/NOTES +++ b/src/go/types/NOTES @@ -4,6 +4,8 @@ so we have a better track record. I only switched to this file in Nov 2019, henc ---------------------------------------------------------------------------------------------------- TODO +- implement type-checking for type parameters with pointer designation in contracts +- figure out how to translate methods with pointer designation into interface bounds - review use of Contract.TParams field - it seems like it's only needed for length checks? - review handling of fields of instantiated generic types (do we need to make them non-parameterized, similar to what we did for the embedded interfaces created by contract embedding?) diff --git a/src/go/types/contracts.go b/src/go/types/contracts.go index 1dae945e76..e20ce1d1e0 100644 --- a/src/go/types/contracts.go +++ b/src/go/types/contracts.go @@ -33,6 +33,9 @@ func (check *Checker) contractDecl(obj *Contract, cdecl *ast.ContractSpec) { // collect constraints for _, c := range cdecl.Constraints { + if c.Star.IsValid() { + check.errorf(c.Star, "pointer designation for type parameters not yet supported (* is ignored)") + } if c.Param != nil { // If a type name is present, it must be one of the contract's type parameters. pos := c.Param.Pos() diff --git a/src/go/types/testdata/tmp.go2 b/src/go/types/testdata/tmp.go2 index fdcef50337..3f2775edb0 100644 --- a/src/go/types/testdata/tmp.go2 +++ b/src/go/types/testdata/tmp.go2 @@ -4,6 +4,15 @@ package p +// TODO(gri) this should work +contract C(T) { + T m() +} + +func _(type T C)(x *T) { + x.m /* ERROR no field or method m */ () +} + /* func f(type T)(T) diff --git a/src/go/types/testdata/todos.go2 b/src/go/types/testdata/todos.go2 index 8739b0997b..8bad5efb2f 100644 --- a/src/go/types/testdata/todos.go2 +++ b/src/go/types/testdata/todos.go2 @@ -8,6 +8,11 @@ package p +// Pointer designation for type parameters is not yet supported. +contract _C(T) { + * /* ERROR not yet supported */ T m() +} + // indexing on generic types containing type parameters in their type list // is not yet supported func _(type T interface { type T })(x T) {