func (r *ReferenceConstraint) HasDefault() bool {
	c, err := r.Resolved()
	if err != nil {
		return false
	}
	return c.HasDefault()
}
HasDefault returns true if the constraint pointed by the reference
has defaults
package jsval
import (
	"errors"
	"sync"
	"github.com/lestrrat/go-pdebug"
)
type RefResolver interface {
	GetReference(string) (Constraint, error)
}
type ConstraintMap struct {
	lock sync.Mutex
	refs map[string]Constraint
}
func (cm ConstraintMap) Len() int {
	return len(cm.refmap())
}
func (cm *ConstraintMap) refmap() map[string]Constraint {
	if cm.refs == nil {
		cm.refs = make(map[string]Constraint)
	}
	return cm.refs
}
func (cm *ConstraintMap) SetReference(name string, c Constraint) {
	cm.lock.Lock()
	defer cm.lock.Unlock()
	refs := cm.refmap()
	refs[name] = c
}
func (cm *ConstraintMap) GetReference(name string) (Constraint, error) {
	cm.lock.Lock()
	defer cm.lock.Unlock()
	refs := cm.refmap()
	c, ok := refs[name]
	if !ok {
		return nil, errors.New("reference '" + name + "' not found")
	}
	return c, nil
}
type ReferenceConstraint struct {
	resolver  RefResolver
	lock      sync.Mutex
	resolved  Constraint
	reference string
}
func Reference(resolver RefResolver) *ReferenceConstraint {
	return &ReferenceConstraint{
		resolver: resolver,
	}
}
func (r *ReferenceConstraint) Resolved() (c Constraint, err error) {
	if pdebug.Enabled {
		g := pdebug.IPrintf("START ReferenceConstraint.Resolved '%s'", r.reference)
		defer func() {
			if err == nil {
				g.IRelease("END ReferenceConstraint.Resolved '%s' (OK)", r.reference)
			} else {
				g.IRelease("END ReferenceConstraint.Resolved '%s' (FAIL): %s", r.reference, err)
			}
		}()
	}
	r.lock.Lock()
	defer r.lock.Unlock()
	if r.resolved != nil {
		if pdebug.Enabled {
			pdebug.Printf("Reference is already resolved")
		}
		return r.resolved, nil
	}
	c, err = r.resolver.GetReference(r.reference)
	if err != nil {
		return nil, err
	}
	r.resolved = c
	return c, nil
}
func (r *ReferenceConstraint) RefersTo(s string) *ReferenceConstraint {
	r.reference = s
	return r
}
func (r *ReferenceConstraint) Default(_ interface{}) {
}
func (r *ReferenceConstraint) DefaultValue() interface{} {
	c, err := r.Resolved()
	if err != nil {
		return nil
	}
	return c.DefaultValue()
}