reject_generic_assign_mismatch.mx raw

   1  // An instantiated generic is identified by its ORIGIN AND ITS ARGUMENTS:
   2  // Box[int32] and Box[uint32] are different types even though they share one
   3  // declaration. stage4 used to compare only the origin, so this assignment was
   4  // accepted while legacy (go/types) rejected it.
   5  //
   6  // expected: cannot use
   7  package main
   8  
   9  type Box[T comparable] struct {
  10  	V T
  11  }
  12  
  13  func main() {
  14  	select {
  15  	case <-shutdown:
  16  		return
  17  	default:
  18  	}
  19  	var a Box[int32]
  20  	a.V = 7
  21  	var b Box[uint32] = a
  22  	println(b.V)
  23  }
  24