Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spurious singleton warning when using register_constant #293

Closed
srenatus opened this issue Jul 30, 2020 · 2 comments
Closed

spurious singleton warning when using register_constant #293

srenatus opened this issue Jul 30, 2020 · 2 comments

Comments

@srenatus
Copy link

With r.rb as

require 'oso'

$polar=<<POLAR
test(b) if
  b = input.foo;
POLAR

input = {"foo" => "baz"}

o = Oso.new
o.load_str($polar)
o.register_constant('input', value: input)

x = Oso::Polar::Variable.new('x')
puts o.query_rule('test', x).force

I get the following output when running the script:

$ bundle exec ruby ../osoq/r.rb
Singleton variable input is unused or undefined, see <https://docs.oso.dev/using/polar-syntax.html#variables>
002:   b = input.foo;
           ^
{"x"=>"baz"}

It seems to work alright, but the warning is wrong?

@samscott89
Copy link
Member

Hey @srenatus! Thanks for the report.

You're getting this warning because you're loading the rule before the constant is registered. If you swap those two lines the warning should go away.

@srenatus
Copy link
Author

🤦 Of course. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants