@@ -663,9 +663,24 @@ func (pr *pkgReader) objInstIdx(info objInfo, dict *readerDict, shaped bool) ir.
663
663
}
664
664
665
665
// objIdx returns the specified object, instantiated with the given
666
- // type arguments, if any. If shaped is true, then the shaped variant
667
- // of the object is returned instead.
666
+ // type arguments, if any.
667
+ // If shaped is true, then the shaped variant of the object is returned
668
+ // instead.
668
669
func (pr * pkgReader ) objIdx (idx pkgbits.Index , implicits , explicits []* types.Type , shaped bool ) ir.Node {
670
+ n , err := pr .objIdxMayFail (idx , implicits , explicits , shaped )
671
+ if err != nil {
672
+ base .Fatalf ("%v" , err )
673
+ }
674
+ return n
675
+ }
676
+
677
+ // objIdxMayFail is equivalent to objIdx, but returns an error rather than
678
+ // failing the build if this object requires type arguments and the incorrect
679
+ // number of type arguments were passed.
680
+ //
681
+ // Other sources of internal failure (such as duplicate definitions) still fail
682
+ // the build.
683
+ func (pr * pkgReader ) objIdxMayFail (idx pkgbits.Index , implicits , explicits []* types.Type , shaped bool ) (ir.Node , error ) {
669
684
rname := pr .newReader (pkgbits .RelocName , idx , pkgbits .SyncObject1 )
670
685
_ , sym := rname .qualifiedIdent ()
671
686
tag := pkgbits .CodeObj (rname .Code (pkgbits .SyncCodeObj ))
@@ -674,22 +689,25 @@ func (pr *pkgReader) objIdx(idx pkgbits.Index, implicits, explicits []*types.Typ
674
689
assert (! sym .IsBlank ())
675
690
switch sym .Pkg {
676
691
case types .BuiltinPkg , types .UnsafePkg :
677
- return sym .Def .(ir.Node )
692
+ return sym .Def .(ir.Node ), nil
678
693
}
679
694
if pri , ok := objReader [sym ]; ok {
680
- return pri .pr .objIdx (pri .idx , nil , explicits , shaped )
695
+ return pri .pr .objIdxMayFail (pri .idx , nil , explicits , shaped )
681
696
}
682
697
if sym .Pkg .Path == "runtime" {
683
- return typecheck .LookupRuntime (sym .Name )
698
+ return typecheck .LookupRuntime (sym .Name ), nil
684
699
}
685
700
base .Fatalf ("unresolved stub: %v" , sym )
686
701
}
687
702
688
- dict := pr .objDictIdx (sym , idx , implicits , explicits , shaped )
703
+ dict , err := pr .objDictIdx (sym , idx , implicits , explicits , shaped )
704
+ if err != nil {
705
+ return nil , err
706
+ }
689
707
690
708
sym = dict .baseSym
691
709
if ! sym .IsBlank () && sym .Def != nil {
692
- return sym .Def .(* ir.Name )
710
+ return sym .Def .(* ir.Name ), nil
693
711
}
694
712
695
713
r := pr .newReader (pkgbits .RelocObj , idx , pkgbits .SyncObject1 )
@@ -725,15 +743,15 @@ func (pr *pkgReader) objIdx(idx pkgbits.Index, implicits, explicits []*types.Typ
725
743
name := do (ir .OTYPE , false )
726
744
setType (name , r .typ ())
727
745
name .SetAlias (true )
728
- return name
746
+ return name , nil
729
747
730
748
case pkgbits .ObjConst :
731
749
name := do (ir .OLITERAL , false )
732
750
typ := r .typ ()
733
751
val := FixValue (typ , r .Value ())
734
752
setType (name , typ )
735
753
setValue (name , val )
736
- return name
754
+ return name , nil
737
755
738
756
case pkgbits .ObjFunc :
739
757
if sym .Name == "init" {
@@ -768,7 +786,7 @@ func (pr *pkgReader) objIdx(idx pkgbits.Index, implicits, explicits []*types.Typ
768
786
}
769
787
770
788
rext .funcExt (name , nil )
771
- return name
789
+ return name , nil
772
790
773
791
case pkgbits .ObjType :
774
792
name := do (ir .OTYPE , true )
@@ -805,13 +823,13 @@ func (pr *pkgReader) objIdx(idx pkgbits.Index, implicits, explicits []*types.Typ
805
823
r .needWrapper (typ )
806
824
}
807
825
808
- return name
826
+ return name , nil
809
827
810
828
case pkgbits .ObjVar :
811
829
name := do (ir .ONAME , false )
812
830
setType (name , r .typ ())
813
831
rext .varExt (name )
814
- return name
832
+ return name , nil
815
833
}
816
834
}
817
835
@@ -908,7 +926,7 @@ func shapify(targ *types.Type, basic bool) *types.Type {
908
926
}
909
927
910
928
// objDictIdx reads and returns the specified object dictionary.
911
- func (pr * pkgReader ) objDictIdx (sym * types.Sym , idx pkgbits.Index , implicits , explicits []* types.Type , shaped bool ) * readerDict {
929
+ func (pr * pkgReader ) objDictIdx (sym * types.Sym , idx pkgbits.Index , implicits , explicits []* types.Type , shaped bool ) ( * readerDict , error ) {
912
930
r := pr .newReader (pkgbits .RelocObjDict , idx , pkgbits .SyncObject1 )
913
931
914
932
dict := readerDict {
@@ -919,7 +937,7 @@ func (pr *pkgReader) objDictIdx(sym *types.Sym, idx pkgbits.Index, implicits, ex
919
937
nexplicits := r .Len ()
920
938
921
939
if nimplicits > len (implicits ) || nexplicits != len (explicits ) {
922
- base . Fatalf ("%v has %v+%v params, but instantiated with %v+%v args" , sym , nimplicits , nexplicits , len (implicits ), len (explicits ))
940
+ return nil , fmt . Errorf ("%v has %v+%v params, but instantiated with %v+%v args" , sym , nimplicits , nexplicits , len (implicits ), len (explicits ))
923
941
}
924
942
925
943
dict .targs = append (implicits [:nimplicits :nimplicits ], explicits ... )
@@ -984,7 +1002,7 @@ func (pr *pkgReader) objDictIdx(sym *types.Sym, idx pkgbits.Index, implicits, ex
984
1002
dict .itabs [i ] = itabInfo {typ : r .typInfo (), iface : r .typInfo ()}
985
1003
}
986
1004
987
- return & dict
1005
+ return & dict , nil
988
1006
}
989
1007
990
1008
func (r * reader ) typeParamNames () {
@@ -2529,7 +2547,10 @@ func (pr *pkgReader) objDictName(idx pkgbits.Index, implicits, explicits []*type
2529
2547
base .Fatalf ("unresolved stub: %v" , sym )
2530
2548
}
2531
2549
2532
- dict := pr .objDictIdx (sym , idx , implicits , explicits , false )
2550
+ dict , err := pr .objDictIdx (sym , idx , implicits , explicits , false )
2551
+ if err != nil {
2552
+ base .Fatalf ("%v" , err )
2553
+ }
2533
2554
2534
2555
return pr .dictNameOf (dict )
2535
2556
}
0 commit comments