concat_text_forms.mx raw

   1  /*
   2  Every legal shape of '|', and the bitwise OR it still is for numbers.
   3  
   4  The mixed text/other case is rejected (reject_concat_non_text); this fixture
   5  pins the other side of the same rule, because a check that rejects too much is
   6  as wrong as one that rejects too little: text is BOTH spellings (string and
   7  []byte are one type), a named string type is text through its underlying type,
   8  and two non-text operands are a bitwise OR and must keep working.
   9  */
  10  package main
  11  
  12  type label string
  13  
  14  func main() {
  15  	// Termination: a batch program must still be stoppable, so the entry
  16  	// handles the channel the runtime closes on SIGINT/SIGTERM.
  17  	select {
  18  	case <-shutdown:
  19  		return
  20  	default:
  21  	}
  22  
  23  	var n int64 = 5
  24  	var raw []byte = "y"
  25  	var l label = "L"
  26  
  27  	s := "x=" | "a" | raw | l
  28  	if s != "x=ayL" {
  29  		panic("string|[]byte|named-string = " | s)
  30  	}
  31  
  32  	// '+' and '+=' are the TEXT rules' other half: they are refused for text in
  33  	// user code (reject_plus_text, reject_plusassign_text) and must stay legal
  34  	// for numbers here. The first attempt at that rule used a predicate that
  35  	// said yes to every Basic type and rejected `n += 3`, so the numeric forms
  36  	// are part of this fixture.
  37  	acc := n
  38  	acc += 3
  39  	sum := acc + 4
  40  	if sum != 12 {
  41  		panic("numeric += / + is wrong")
  42  	}
  43  
  44  	or := (n | 2) | 8
  45  	if or != 15 {
  46  		// No .String() here on purpose: the builtin Stringer bodies are native
  47  		// only (moxie.stringer is off for wasm), so a fixture that prints a
  48  		// number cannot compile for the wasm target - and this one should.
  49  		panic("bitwise OR is wrong")
  50  	}
  51  
  52  	println("concat text forms ok")
  53  }
  54