()
| 967 | } |
| 968 | |
| 969 | func (e *Env) initChecker() (*checker.Env, error) { |
| 970 | e.chkOnce.Do(func() { |
| 971 | chkOpts := []checker.Option{} |
| 972 | chkOpts = append(chkOpts, e.chkOpts...) |
| 973 | chkOpts = append(chkOpts, |
| 974 | checker.CrossTypeNumericComparisons( |
| 975 | e.HasFeature(featureCrossTypeNumericComparisons))) |
| 976 | chkOpts = append(chkOpts, |
| 977 | checker.JSONFieldNames(e.HasFeature(featureJSONFieldNames))) |
| 978 | |
| 979 | if e.parent != nil && e.funcsShared { |
| 980 | parentChk, err := e.parent.initChecker() |
| 981 | if err != nil { |
| 982 | e.setCheckerOrError(nil, err) |
| 983 | return |
| 984 | } |
| 985 | chkOpts = append(chkOpts, checker.ValidatedDeclarations(parentChk)) |
| 986 | } |
| 987 | |
| 988 | ce, err := checker.NewEnv(e.Container, e.provider, chkOpts...) |
| 989 | if err != nil { |
| 990 | e.setCheckerOrError(nil, err) |
| 991 | return |
| 992 | } |
| 993 | // Add the statically configured declarations. |
| 994 | err = ce.AddIdents(e.variables...) |
| 995 | if err != nil { |
| 996 | e.setCheckerOrError(nil, err) |
| 997 | return |
| 998 | } |
| 999 | // Add the function declarations which are derived from the FunctionDecl instances. |
| 1000 | if e.parent == nil || !e.funcsShared { |
| 1001 | for _, fn := range e.functions { |
| 1002 | if fn.IsDeclarationDisabled() { |
| 1003 | continue |
| 1004 | } |
| 1005 | err = ce.AddFunctions(fn) |
| 1006 | if err != nil { |
| 1007 | e.setCheckerOrError(nil, err) |
| 1008 | return |
| 1009 | } |
| 1010 | } |
| 1011 | } |
| 1012 | // Add function declarations here separately. |
| 1013 | e.setCheckerOrError(ce, nil) |
| 1014 | }) |
| 1015 | return e.getCheckerOrError() |
| 1016 | } |
| 1017 | |
| 1018 | // setCheckerOrError sets the checker.Env or error state in a concurrency-safe manner |
| 1019 | func (e *Env) setCheckerOrError(chk *checker.Env, chkErr error) { |
no test coverage detected