Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
cue: deprecate Instance.(Doc|Fill)
Browse files Browse the repository at this point in the history
Change-Id: Id24cd90dab675ef7835a7cb6aba5652e008751bf
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/9443
Reviewed-by: CUE cueckoo <[email protected]>
Reviewed-by: Paul Jolly <[email protected]>
  • Loading branch information
mpvl committed Apr 21, 2021
1 parent c290772 commit 618c10c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 35 deletions.
41 changes: 7 additions & 34 deletions cue/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
"cuelang.org/go/internal"
"cuelang.org/go/internal/core/adt"
"cuelang.org/go/internal/core/compile"
"cuelang.org/go/internal/core/convert"
"cuelang.org/go/internal/core/eval"
"cuelang.org/go/internal/core/runtime"
)

Expand Down Expand Up @@ -260,17 +258,10 @@ func (inst *Instance) ID() string {
}

// Doc returns the package comments for this instance.
//
// Deprecated: use inst.Value().Doc()
func (inst *Instance) Doc() []*ast.CommentGroup {
var docs []*ast.CommentGroup
if inst.inst == nil {
return nil
}
for _, f := range inst.inst.Files {
if c := internal.FileComment(f); c != nil {
docs = append(docs, c)
}
}
return docs
return inst.Value().Doc()
}

// Value returns the root value of the configuration. If the configuration
Expand Down Expand Up @@ -403,37 +394,19 @@ func (inst *Instance) LookupField(path ...string) (f FieldInfo, err error) {
// Values may be any Go value that can be converted to CUE, an ast.Expr or
// a Value. In the latter case, it will panic if the Value is not from the same
// Runtime.
//
// Deprecated: use Value.FillPath()
func (inst *Instance) Fill(x interface{}, path ...string) (*Instance, error) {
for i := len(path) - 1; i >= 0; i-- {
x = map[string]interface{}{path[i]: x}
}
a := make([]adt.Conjunct, len(inst.root.Conjuncts))
copy(a, inst.root.Conjuncts)
u := &adt.Vertex{Conjuncts: a}
v := inst.Value().Fill(x, path...)

if v, ok := x.(Value); ok {
if inst.index != v.idx {
panic("value of type Value is not created with same Runtime as Instance")
}
for _, c := range v.v.Conjuncts {
u.AddConjunct(c)
}
} else {
ctx := eval.NewContext(inst.index, nil)
expr := convert.GoValueToExpr(ctx, true, x)
u.AddConjunct(adt.MakeRootConjunct(nil, expr))
u.Finalize(ctx)
}
inst = addInst(inst.index, &Instance{
root: u,
root: v.v,
inst: nil,

// Omit ImportPath to indicate this is not an importable package.
Dir: inst.Dir,
PkgName: inst.PkgName,
Incomplete: inst.Incomplete,

// complete: true,
})
return inst, nil
}
2 changes: 1 addition & 1 deletion cue/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2799,7 +2799,7 @@ Another Foo.
})
}
want := "foobar defines at least foo.\n"
if got := docStr(inst.Doc()); got != want {
if got := docStr(inst.Value().Doc()); got != want {
t.Errorf("pkg: got:\n%vwant:\n%v", got, want)
}
}
Expand Down

0 comments on commit 618c10c

Please sign in to comment.