reject_missing_import.mx raw

   1  // expected: cannot find package
   2  //
   3  // An import whose path resolves to no package is an ERROR, in every position.
   4  //
   5  // Until round 103 this compiler skipped such an import when the importer was a
   6  // dependency (only the package the build was ASKED for was reported), so a
   7  // blank import of a package that does not exist compiled to nothing and the
   8  // build returned 0. legacy has always answered `package %q not found`
   9  // (loader/mxlist.go resolveDir), so this is the missing half of a rule both
  10  // compilers must share.
  11  //
  12  // What it hid, measured: four entries of the phase-1b stdlib sweep -
  13  // encoding/json, encoding/xml, regexp and text/template - name packages that
  14  // do not exist in this tree at all (encoding/json and encoding/xml went with
  15  // the reflect/any exodus in 3b6e25e8 and 4da18fb0; regexp and text/template
  16  // with the same sweep), and `_ "encoding/json"` compiled to nothing while the
  17  // sweep reported "41 packages ok". Ten more files (internal/lazyregexp,
  18  // internal/lazytemplate, internal/coverage/{cfile,pods},
  19  // internal/trace/{testtrace,traceviewer}, internal/profile/prune.mx,
  20  // index/suffixarray, and the stale _mxc_stage4/{syntax,token,cmd/mxlex}
  21  // copies) imported packages that do not exist and were never built by
  22  // anything - they are removed in the same round.
  23  //
  24  // The blank import is the case that must not regress: a used import fails
  25  // later anyway, but a blank one has no symbol to miss, and a side-effect
  26  // import that silently does not happen is the worst version of this bug.
  27  package main
  28  
  29  import (
  30  	_ "nonexistent/pkg"
  31  )
  32  
  33  func main() {
  34  	println("unreachable")
  35  }
  36