Skip to content

Commit

Permalink
internal/core/runtime: check non-existing builtin packages earlier
Browse files Browse the repository at this point in the history
This used to be done during evaluation instead.

Fixes #1457

Signed-off-by: Marcel van Lohuizen <[email protected]>

Change-Id: Iaf9a1740ffe480a8c99bba0b0906bffdcc9908e7
Signed-off-by: Marcel van Lohuizen <[email protected]>
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/530899
Reviewed-by: Paul Jolly <[email protected]>
  • Loading branch information
mpvl committed Jan 11, 2022
1 parent 8fbaf81 commit d4d0f14
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
3 changes: 3 additions & 0 deletions cue/load/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ func GenPath(root string) string {

// A Config configures load behavior.
type Config struct {
// TODO: allow passing a cuecontext to be able to lookup and verify builtin
// packages at loading time.

// Context specifies the context for the load operation.
// If the context is cancelled, the loader may stop early
// and return an ErrCancelled error.
Expand Down
17 changes: 2 additions & 15 deletions cue/testdata/packages/builtin.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,8 @@ foo: [
y,
]
-- out/eval --
Errors:
foo.0: cannot find package "x/y":
./x.cue:4:2

Result:
(_|_){
// [eval]
foo: (_|_){
// [eval]
0: (_|_){
// [eval] foo.0: cannot find package "x/y":
// ./x.cue:4:2
}
}
}
builtin package "x/y" undefined:
./x.cue:1:8
-- out/compile --
--- x.cue
{
Expand Down
5 changes: 4 additions & 1 deletion internal/core/runtime/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,11 @@ func (x *Runtime) buildSpec(cfg *Config, b *build.Instance, spec *ast.ImportSpec
return errors.Newf(spec.Pos(),
"package %q imported but not defined in %s",
info.ID, b.ImportPath)
} else if x.index.builtinPaths[info.ID] == nil {
return errors.Newf(spec.Pos(),
"builtin package %q undefined", info.ID)
}
return nil // TODO: check the builtin package exists here.
return nil
}

if v := x.getNodeFromInstance(pkg); v != nil {
Expand Down

0 comments on commit d4d0f14

Please sign in to comment.