main.mx raw

   1  /*
   2  A sized literal of a QUALIFIED named slice type: `lib.Nat{:3}`.
   3  
   4  Named slice types are allowed and can be sized with the `T{:n}` form. When T
   5  is qualified, the qualifier is part of the type expression the literal lowers
   6  to; the text rewriter used to start at the type name and emitted
   7  `lib.__slicealloc(Nat, 3)`, which is undefined in the importing package.
   8  */
   9  package main
  10  
  11  import "tests/regressions/should_compile/named_slice_sized_literal/lib"
  12  
  13  func main() {
  14  	// Termination: a batch program must still be stoppable, so the entry
  15  	// handles the channel the runtime closes on SIGINT/SIGTERM.
  16  	select {
  17  	case <-shutdown:
  18  		return
  19  	default:
  20  	}
  21  
  22  	var n lib.Nat = lib.Nat{:3}
  23  	n[0] = 1
  24  	n[1] = 2
  25  	n[2] = 3
  26  	if lib.Sum(n) != 6 || len(n) != 3 || cap(n) != 3 {
  27  		panic("lib.Nat{:3} did not size a named slice")
  28  	}
  29  	var local lib.Nat = lib.Nat{:2:4}
  30  	local[1] = 5
  31  	if len(local) != 2 || cap(local) != 4 || local[1] != 5 {
  32  		panic("lib.Nat{:2:4} did not size a named slice")
  33  	}
  34  	println("named slice sized literal ok")
  35  }
  36