Source file test/fixedbugs/bug248.dir/bug2.go

     1  // Copyright 2010 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file
     4  
     5  package s
     6  
     7  import (
     8  	p0 "./bug0"
     9  	p1 "./bug1"
    10  )
    11  
    12  // both p0.T and p1.T are struct { X, Y int }.
    13  
    14  var v0 p0.T
    15  var v1 p1.T
    16  
    17  // interfaces involving the two
    18  
    19  type I0 interface {
    20  	M(p0.T)
    21  }
    22  
    23  type I1 interface {
    24  	M(p1.T)
    25  }
    26  
    27  // t0 satisfies I0 and p0.I
    28  type t0 int
    29  
    30  func (t0) M(p0.T) {}
    31  
    32  // t1 satisfies I1 and p1.I
    33  type t1 float64
    34  
    35  func (t1) M(p1.T) {}
    36  
    37  // check static interface assignments
    38  var i0 I0 = t0(0) // ok
    39  var i1 I1 = t1(0) // ok
    40  
    41  var i2 I0 = t1(0) // ERROR "does not implement|incompatible"
    42  var i3 I1 = t0(0) // ERROR "does not implement|incompatible"
    43  
    44  var p0i p0.I = t0(0) // ok
    45  var p1i p1.I = t1(0) // ok
    46  
    47  var p0i1 p0.I = t1(0) // ERROR "does not implement|incompatible"
    48  var p0i2 p1.I = t0(0) // ERROR "does not implement|incompatible"
    49  
    50  func foobar() {
    51  	// check that cannot assign one to the other,
    52  	// but can convert.
    53  	v0 = v1 // ERROR "assign|cannot use"
    54  	v1 = v0 // ERROR "assign|cannot use"
    55  
    56  	v0 = p0.T(v1)
    57  	v1 = p1.T(v0)
    58  
    59  	i0 = i1   // ERROR "cannot use|incompatible"
    60  	i1 = i0   // ERROR "cannot use|incompatible"
    61  	p0i = i1  // ERROR "cannot use|incompatible"
    62  	p1i = i0  // ERROR "cannot use|incompatible"
    63  	i0 = p1i  // ERROR "cannot use|incompatible"
    64  	i1 = p0i  // ERROR "cannot use|incompatible"
    65  	p0i = p1i // ERROR "cannot use|incompatible"
    66  	p1i = p0i // ERROR "cannot use|incompatible"
    67  
    68  	i0 = p0i
    69  	p0i = i0
    70  
    71  	i1 = p1i
    72  	p1i = i1
    73  }
    74  

View as plain text