]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/go/types/mono.go
go/types, types2: implement Alias proposal (export API)
[gostls13.git] / src / go / types / mono.go
index 84e1e971b67471d3adb8976ab6fe98bb1b9dfbdb..74113392149fbdc1362af3d085496b8daf907b12 100644 (file)
@@ -7,6 +7,7 @@ package types
 import (
        "go/ast"
        "go/token"
+       . "internal/types/errors"
 )
 
 // This file implements a check to validate that a Go package doesn't
@@ -138,7 +139,7 @@ func (check *Checker) reportInstanceLoop(v int) {
        // TODO(mdempsky): Pivot stack so we report the cycle from the top?
 
        obj0 := check.mono.vertices[v].obj
-       check.errorf(obj0, _InvalidInstanceCycle, "instantiation cycle:")
+       check.error(obj0, InvalidInstanceCycle, "instantiation cycle:")
 
        qf := RelativeTo(check.pkg)
        for _, v := range stack {
@@ -149,9 +150,9 @@ func (check *Checker) reportInstanceLoop(v int) {
                default:
                        panic("unexpected type")
                case *Named:
-                       check.errorf(atPos(edge.pos), _InvalidInstanceCycle, "\t%s implicitly parameterized by %s", obj.Name(), TypeString(edge.typ, qf)) // secondary error, \t indented
+                       check.errorf(atPos(edge.pos), InvalidInstanceCycle, "\t%s implicitly parameterized by %s", obj.Name(), TypeString(edge.typ, qf)) // secondary error, \t indented
                case *TypeParam:
-                       check.errorf(atPos(edge.pos), _InvalidInstanceCycle, "\t%s instantiated as %s", obj.Name(), TypeString(edge.typ, qf)) // secondary error, \t indented
+                       check.errorf(atPos(edge.pos), InvalidInstanceCycle, "\t%s instantiated as %s", obj.Name(), TypeString(edge.typ, qf)) // secondary error, \t indented
                }
        }
 }
@@ -205,7 +206,7 @@ func (w *monoGraph) assign(pkg *Package, pos token.Pos, tpar *TypeParam, targ Ty
        // type parameters.
        var do func(typ Type)
        do = func(typ Type) {
-               switch typ := typ.(type) {
+               switch typ := Unalias(typ).(type) {
                default:
                        panic("unexpected type")
 
@@ -281,7 +282,7 @@ func (w *monoGraph) localNamedVertex(pkg *Package, named *Named) int {
        // parameters that it's implicitly parameterized by.
        for scope := obj.Parent(); scope != root; scope = scope.Parent() {
                for _, elem := range scope.elems {
-                       if elem, ok := elem.(*TypeName); ok && !elem.IsAlias() && elem.Pos() < obj.Pos() {
+                       if elem, ok := elem.(*TypeName); ok && !elem.IsAlias() && cmpPos(elem.Pos(), obj.Pos()) < 0 {
                                if tpar, ok := elem.Type().(*TypeParam); ok {
                                        if idx < 0 {
                                                idx = len(w.vertices)