@@ -840,28 +840,15 @@ func IsAddressable(n Node) bool {
840
840
return false
841
841
}
842
842
843
- var Implements = func (t , iface * types.Type ) bool {
844
- panic ("unreachable" )
845
- }
846
-
847
- // StaticType is like StaticValue but for types.
843
+ // StaticType is like StaticValue, but also follows ODOTTYPE and OCONVIFACE.
848
844
func StaticType (n Node ) * types.Type {
849
- out , typs := staticValue (n , true )
845
+ out := staticValue (n , true )
850
846
851
847
typ := out .Type ()
852
848
if typ .IsInterface () {
853
849
return nil
854
850
}
855
851
856
- // Make sure that every type assertion that involves interfaes is satisfied.
857
- for _ , t := range typs {
858
- if t .IsInterface () {
859
- if ! Implements (typ , t ) {
860
- return nil
861
- }
862
- }
863
- }
864
-
865
852
return typ
866
853
}
867
854
@@ -880,16 +867,11 @@ func StaticType(n Node) *types.Type {
880
867
// calling StaticValue on the "int(y)" expression returns the outer
881
868
// "g()" expression.
882
869
func StaticValue (n Node ) Node {
883
- v , t := staticValue (n , false )
884
- if len (t ) != 0 {
885
- base .Fatalf ("len(t) != 0; len(t) = %v" , len (t ))
886
- }
887
- return v
870
+ return staticValue (n , false )
888
871
889
872
}
890
873
891
- func staticValue (n Node , forDevirt bool ) (Node , []* types.Type ) {
892
- typeAssertTypes := []* types.Type {}
874
+ func staticValue (n Node , forDevirt bool ) Node {
893
875
for {
894
876
switch n1 := n .(type ) {
895
877
case * ConvExpr :
@@ -898,7 +880,6 @@ func staticValue(n Node, forDevirt bool) (Node, []*types.Type) {
898
880
continue
899
881
}
900
882
if forDevirt && n1 .Op () == OCONVIFACE {
901
- typeAssertTypes = append (typeAssertTypes , n1 .Type ())
902
883
n = n1 .X
903
884
continue
904
885
}
@@ -912,15 +893,14 @@ func staticValue(n Node, forDevirt bool) (Node, []*types.Type) {
912
893
continue
913
894
case * TypeAssertExpr :
914
895
if forDevirt && n1 .Op () == ODOTTYPE {
915
- typeAssertTypes = append (typeAssertTypes , n1 .Type ())
916
896
n = n1 .X
917
897
continue
918
898
}
919
899
}
920
900
921
901
n1 := staticValue1 (n )
922
902
if n1 == nil {
923
- return n , typeAssertTypes
903
+ return n
924
904
}
925
905
n = n1
926
906
}
0 commit comments