Skip to content

Commit

Permalink
ast: Unexport the GetPrefix function
Browse files Browse the repository at this point in the history
This change does not affect any functionality it just unexports the
GetPrefix function to keep the TypeEnv API as mimimal as possible. The
function has been moved into check.go to live next to other similar
helpers (e.g., getArgTypes).

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
  • Loading branch information
tsandall committed Apr 2, 2021
1 parent 898d010 commit ed75f77
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
19 changes: 18 additions & 1 deletion ast/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (tc *typeChecker) checkRule(env *TypeEnv, rule *Rule) {
tc.err([]*Error{err})
continue
}
prefixRef, t := env.GetPrefix(ref)
prefixRef, t := getPrefix(env, ref)
if t == nil || len(prefixRef) == len(ref) {
env.tree.Put(ref, refType)
} else {
Expand Down Expand Up @@ -1015,6 +1015,23 @@ func getArgTypes(env *TypeEnv, args []*Term) []types.Type {
return pre
}

// getPrefix returns the shortest prefix of ref that exists in env
func getPrefix(env *TypeEnv, ref Ref) (Ref, types.Type) {
if len(ref) == 1 {
t := env.Get(ref)
if t != nil {
return ref, t
}
}
for i := 1; i < len(ref); i++ {
t := env.Get(ref[:i])
if t != nil {
return ref[:i], t
}
}
return nil, nil
}

// override takes a type t and returns a type obtained from t where the path represented by ref within it has type o (overriding the original type of that path)
func override(ref Ref, t types.Type, o types.Type, rule *Rule) (types.Type, *Error) {
newStaticProps := []*types.StaticProperty{}
Expand Down
17 changes: 0 additions & 17 deletions ast/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,6 @@ func (env *TypeEnv) WithSchemas(schemas *SchemaSet) *TypeEnv {
return env
}

// GetPrefix returns the shortest prefix of ref that exists in env
func (env *TypeEnv) GetPrefix(ref Ref) (Ref, types.Type) {
if len(ref) == 1 {
t := env.Get(ref)
if t != nil {
return ref, t
}
}
for i := 1; i < len(ref); i++ {
t := env.Get(ref[:i])
if t != nil {
return ref[:i], t
}
}
return nil, nil
}

// Get returns the type of x.
func (env *TypeEnv) Get(x interface{}) types.Type {

Expand Down

0 comments on commit ed75f77

Please sign in to comment.