Source file test/fixedbugs/issue43112.go

     1  // compile
     2  
     3  // Copyright 2020 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  package p
     8  
     9  type Symbol interface{}
    10  
    11  type Value interface {
    12  	String() string
    13  }
    14  
    15  type Object interface {
    16  	String() string
    17  }
    18  
    19  type Scope struct {
    20  	outer *Scope
    21  	elems map[string]Object
    22  }
    23  
    24  func (s *Scope) findouter(name string) (*Scope, Object) {
    25  	return s.outer.findouter(name)
    26  }
    27  
    28  func (s *Scope) Resolve(name string) (sym Symbol) {
    29  	if _, obj := s.findouter(name); obj != nil {
    30  		sym = obj.(Symbol)
    31  	}
    32  	return
    33  }
    34  
    35  type ScopeName struct {
    36  	scope *Scope
    37  }
    38  
    39  func (n *ScopeName) Get(name string) (Value, error) {
    40  	return n.scope.Resolve(name).(Value), nil
    41  }
    42  

View as plain text