Source file test/interface/pointer.go

     1  // errorcheck
     2  
     3  // Copyright 2009 The Go Authors. All rights reserved.
     4  // Use of this source code is governed by a BSD-style
     5  // license that can be found in the LICENSE file.
     6  
     7  // Test that interface{M()} = *interface{M()} produces a compiler error.
     8  // Does not compile.
     9  
    10  package main
    11  
    12  type Inst interface {
    13  	Next() *Inst
    14  }
    15  
    16  type Regexp struct {
    17  	code  []Inst
    18  	start Inst
    19  }
    20  
    21  type Start struct {
    22  	foo *Inst
    23  }
    24  
    25  func (start *Start) Next() *Inst { return nil }
    26  
    27  func AddInst(Inst) *Inst {
    28  	print("ok in addinst\n")
    29  	return nil
    30  }
    31  
    32  func main() {
    33  	print("call addinst\n")
    34  	var _ Inst = AddInst(new(Start)) // ERROR "pointer to interface|incompatible type"
    35  	print("return from  addinst\n")
    36  	var _ *Inst = new(Start) // ERROR "pointer to interface|incompatible type"
    37  }
    38  

View as plain text