@@ -663,9 +663,24 @@ func (pr *pkgReader) objInstIdx(info objInfo, dict *readerDict, shaped bool) ir.
663663}
664664
665665// 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.
668669func (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 ) {
669684 rname := pr .newReader (pkgbits .RelocName , idx , pkgbits .SyncObject1 )
670685 _ , sym := rname .qualifiedIdent ()
671686 tag := pkgbits .CodeObj (rname .Code (pkgbits .SyncCodeObj ))
@@ -674,22 +689,25 @@ func (pr *pkgReader) objIdx(idx pkgbits.Index, implicits, explicits []*types.Typ
674689 assert (! sym .IsBlank ())
675690 switch sym .Pkg {
676691 case types .BuiltinPkg , types .UnsafePkg :
677- return sym .Def .(ir.Node )
692+ return sym .Def .(ir.Node ), nil
678693 }
679694 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 )
681696 }
682697 if sym .Pkg .Path == "runtime" {
683- return typecheck .LookupRuntime (sym .Name )
698+ return typecheck .LookupRuntime (sym .Name ), nil
684699 }
685700 base .Fatalf ("unresolved stub: %v" , sym )
686701 }
687702
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+ }
689707
690708 sym = dict .baseSym
691709 if ! sym .IsBlank () && sym .Def != nil {
692- return sym .Def .(* ir.Name )
710+ return sym .Def .(* ir.Name ), nil
693711 }
694712
695713 r := pr .newReader (pkgbits .RelocObj , idx , pkgbits .SyncObject1 )
@@ -725,15 +743,15 @@ func (pr *pkgReader) objIdx(idx pkgbits.Index, implicits, explicits []*types.Typ
725743 name := do (ir .OTYPE , false )
726744 setType (name , r .typ ())
727745 name .SetAlias (true )
728- return name
746+ return name , nil
729747
730748 case pkgbits .ObjConst :
731749 name := do (ir .OLITERAL , false )
732750 typ := r .typ ()
733751 val := FixValue (typ , r .Value ())
734752 setType (name , typ )
735753 setValue (name , val )
736- return name
754+ return name , nil
737755
738756 case pkgbits .ObjFunc :
739757 if sym .Name == "init" {
@@ -768,7 +786,7 @@ func (pr *pkgReader) objIdx(idx pkgbits.Index, implicits, explicits []*types.Typ
768786 }
769787
770788 rext .funcExt (name , nil )
771- return name
789+ return name , nil
772790
773791 case pkgbits .ObjType :
774792 name := do (ir .OTYPE , true )
@@ -805,13 +823,13 @@ func (pr *pkgReader) objIdx(idx pkgbits.Index, implicits, explicits []*types.Typ
805823 r .needWrapper (typ )
806824 }
807825
808- return name
826+ return name , nil
809827
810828 case pkgbits .ObjVar :
811829 name := do (ir .ONAME , false )
812830 setType (name , r .typ ())
813831 rext .varExt (name )
814- return name
832+ return name , nil
815833 }
816834}
817835
@@ -908,7 +926,7 @@ func shapify(targ *types.Type, basic bool) *types.Type {
908926}
909927
910928// 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 ) {
912930 r := pr .newReader (pkgbits .RelocObjDict , idx , pkgbits .SyncObject1 )
913931
914932 dict := readerDict {
@@ -919,7 +937,7 @@ func (pr *pkgReader) objDictIdx(sym *types.Sym, idx pkgbits.Index, implicits, ex
919937 nexplicits := r .Len ()
920938
921939 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 ))
923941 }
924942
925943 dict .targs = append (implicits [:nimplicits :nimplicits ], explicits ... )
@@ -984,7 +1002,7 @@ func (pr *pkgReader) objDictIdx(sym *types.Sym, idx pkgbits.Index, implicits, ex
9841002 dict .itabs [i ] = itabInfo {typ : r .typInfo (), iface : r .typInfo ()}
9851003 }
9861004
987- return & dict
1005+ return & dict , nil
9881006}
9891007
9901008func (r * reader ) typeParamNames () {
@@ -2529,7 +2547,10 @@ func (pr *pkgReader) objDictName(idx pkgbits.Index, implicits, explicits []*type
25292547 base .Fatalf ("unresolved stub: %v" , sym )
25302548 }
25312549
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+ }
25332554
25342555 return pr .dictNameOf (dict )
25352556}
0 commit comments