mirror of https://github.com/golang/go.git
go/types: make tests pass again
Disallow parametrized alias types again. They need a bit more work. Change-Id: I90fd101a4c61f8693ee850c5dbd6849a60b85bdc
This commit is contained in:
parent
52934f1b1e
commit
b8b66e1708
|
|
@ -100,6 +100,7 @@ var tests = [][]string{
|
|||
{"testdata/issue6977.src"},
|
||||
|
||||
// Go 2 tests (type parameters and contracts)
|
||||
// {"testdata/tmp.go2"}, // used for ad-hoc tests - file contents transient, excluded from tests
|
||||
{"testdata/typeparams.go2"},
|
||||
{"testdata/typeinst.go2"},
|
||||
{"testdata/typeinst2.go2"},
|
||||
|
|
|
|||
|
|
@ -96,12 +96,15 @@ func (s *subster) typ(typ Type) (res Type) {
|
|||
|
||||
case *Named:
|
||||
underlying := s.typ(t.underlying)
|
||||
//s.check.dump(" underlying = %s", underlying)
|
||||
//s.check.dump("t.underlying = %s", t.underlying)
|
||||
if underlying != t.underlying {
|
||||
// create a new named type - for now use printed type in name
|
||||
// TODO(gri) use type map to map types to indices
|
||||
// TODO(gri) consider type map to map types to indices (on the other hand, a type string seems just as good)
|
||||
if len(t.methods) > 0 {
|
||||
panic("cannot handle instantiation of types with methods yet")
|
||||
}
|
||||
// TODO(gri) review name creation and factor out
|
||||
name := t.obj.name + typesString(s.targs)
|
||||
tname, found := s.check.typMap[name]
|
||||
if !found {
|
||||
|
|
|
|||
|
|
@ -482,7 +482,7 @@ func make1() {
|
|||
}
|
||||
|
||||
func make2() {
|
||||
f1 /* ERROR not used */ := func() (x []int) { return }
|
||||
f1 := func() (x []int) { return }
|
||||
_ = make(f0 /* ERROR not a type */ ())
|
||||
_ = make(f1 /* ERROR not a type */ ())
|
||||
}
|
||||
|
|
@ -502,7 +502,7 @@ func new1() {
|
|||
}
|
||||
|
||||
func new2() {
|
||||
f1 /* ERROR not used */ := func() (x []int) { return }
|
||||
f1 := func() (x []int) { return }
|
||||
_ = new(f0 /* ERROR not a type */ ())
|
||||
_ = new(f1 /* ERROR not a type */ ())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
// Copyright 2019 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package p
|
||||
|
||||
type A(type P, Q) = P
|
||||
|
||||
var x A(int, string)
|
||||
|
||||
type T(type P) struct {
|
||||
f A(P, string)
|
||||
}
|
||||
|
|
@ -42,22 +42,23 @@ type _ T1 /* ERROR got 0 arguments but 1 type parameters */ ()
|
|||
type _ T1(x /* ERROR not a type */ )
|
||||
type _ T1 /* ERROR got 2 arguments but 1 type parameters */ (int, float32)
|
||||
|
||||
var _ A1(int) = x
|
||||
var _ A1(float32) = x // ERROR cannot use x .* as float32
|
||||
// TODO(gri) parameterized alias types don't work correctly
|
||||
// var _ A1(int) = x
|
||||
// var _ A1(float32) = x // ERROR cannot use x .* as float32
|
||||
|
||||
var _ T2(*int) = A2(*int){}
|
||||
var _ T2(*int) = A2 /* ERROR cannot use */ (int){}
|
||||
// var _ T2(*int) = A2(*int){}
|
||||
// var _ T2(*int) = A2 /* ERROR cannot use */ (int){}
|
||||
var _ T2(int) = T2(int){}
|
||||
|
||||
var _ List(int) = []int{1, 2, 3}
|
||||
var _ List([]int) = [][]int{{1, 2, 3}}
|
||||
// var _ List(List(int)) // TODO(gri) cannot not do this yet
|
||||
var _ List(List(List(int)))
|
||||
|
||||
// Parametrized types containing parametrized types
|
||||
|
||||
type T3(type P) = List(P)
|
||||
type T3(type P) List(P)
|
||||
|
||||
// var _ T3(int) = List(int){1, 2, 3} // TODO(gri) cannot do this yet
|
||||
//var _ T3(int) = (T3(int))(List(int){1, 2, 3}) // TODO(gri) cannot do this yet
|
||||
|
||||
|
||||
// TODO
|
||||
|
|
|
|||
|
|
@ -288,19 +288,14 @@ func (check *Checker) typInternal(e ast.Expr, def *Named) Type {
|
|||
}
|
||||
|
||||
named, _ := t.(*Named)
|
||||
if named == nil || named.obj == nil {
|
||||
check.errorf(e.Pos(), "cannot instantiate type without a name")
|
||||
break
|
||||
}
|
||||
|
||||
tname := named.obj
|
||||
if !tname.IsParametrized() {
|
||||
check.errorf(e.Pos(), "%s is not a parametrized type", tname.name)
|
||||
if named == nil || named.obj == nil || !named.obj.IsParametrized() {
|
||||
check.errorf(e.Pos(), "%s is not a parametrized type", t)
|
||||
break
|
||||
}
|
||||
|
||||
// the number of supplied types must match the number of type parameters
|
||||
// TODO(gri) fold into code below - we want to eval args always
|
||||
tname := named.obj
|
||||
if len(e.Args) != len(tname.tparams) {
|
||||
// TODO(gri) provide better error message
|
||||
check.errorf(e.Pos(), "got %d arguments but %d type parameters", len(e.Args), len(tname.tparams))
|
||||
|
|
|
|||
Loading…
Reference in New Issue