@@ -101,97 +101,14 @@ func (check *Checker) indexExpr(x *operand, e *typeparams.IndexExpr) (isFuncInst
101101 return false
102102
103103 case * Interface :
104- // Note: The body of this 'if' statement is the same as the body
105- // of the case for type parameters below. If we keep both
106- // these branches we should factor out the code.
107- if tparamIsIface && isTypeParam (x .typ ) {
108- // TODO(gri) report detailed failure cause for better error messages
109- var key , elem Type // key != nil: we must have all maps
110- mode := variable // non-maps result mode
111- // TODO(gri) factor out closure and use it for non-typeparam cases as well
112- if typ .typeSet ().underIs (func (u Type ) bool {
113- l := int64 (- 1 ) // valid if >= 0
114- var k , e Type // k is only set for maps
115- switch t := u .(type ) {
116- case * Basic :
117- if isString (t ) {
118- e = universeByte
119- mode = value
120- }
121- case * Array :
122- l = t .len
123- e = t .elem
124- if x .mode != variable {
125- mode = value
126- }
127- case * Pointer :
128- if t , _ := under (t .base ).(* Array ); t != nil {
129- l = t .len
130- e = t .elem
131- }
132- case * Slice :
133- e = t .elem
134- case * Map :
135- k = t .key
136- e = t .elem
137- }
138- if e == nil {
139- return false
140- }
141- if elem == nil {
142- // first type
143- length = l
144- key , elem = k , e
145- return true
146- }
147- // all map keys must be identical (incl. all nil)
148- // (that is, we cannot mix maps with other types)
149- if ! Identical (key , k ) {
150- return false
151- }
152- // all element types must be identical
153- if ! Identical (elem , e ) {
154- return false
155- }
156- // track the minimal length for arrays, if any
157- if l >= 0 && l < length {
158- length = l
159- }
160- return true
161- }) {
162- // For maps, the index expression must be assignable to the map key type.
163- if key != nil {
164- index := check .singleIndex (e )
165- if index == nil {
166- x .mode = invalid
167- return false
168- }
169- var k operand
170- check .expr (& k , index )
171- check .assignment (& k , key , "map index" )
172- // ok to continue even if indexing failed - map element type is known
173- x .mode = mapindex
174- x .typ = elem
175- x .expr = e
176- return false
177- }
178-
179- // no maps
180- valid = true
181- x .mode = mode
182- x .typ = elem
183- }
104+ if ! isTypeParam (x .typ ) {
105+ break
184106 }
185- case * TypeParam :
186- // Note: The body of this case is the same as the body of the 'if'
187- // statement in the interface case above. If we keep both
188- // these branches we should factor out the code.
189107 // TODO(gri) report detailed failure cause for better error messages
190- assert (! tparamIsIface )
191108 var key , elem Type // key != nil: we must have all maps
192109 mode := variable // non-maps result mode
193110 // TODO(gri) factor out closure and use it for non-typeparam cases as well
194- if typ .underIs (func (u Type ) bool {
111+ if typ .typeSet (). underIs (func (u Type ) bool {
195112 l := int64 (- 1 ) // valid if >= 0
196113 var k , e Type // k is only set for maps
197114 switch t := u .(type ) {
0 commit comments