Closed fishonamos closed 3 months ago
@fishonamos hi, your code will not compile because NewScopeManager
takes a map[string]any
as argument.
What you can do instead is calling *hinter.DefaultNewScopeManager()
, and DefaultNewScopeManager
will call NewScopeManager
for you passing an empty array as argument.
Basically, you have 2 possibilities:
ctx
ctx := &hinter.HintRunnerContext{
ScopeManager: *hinter.DefaultNewScopeManager(),
}
ctx
an calling InitializeScopeManager
, passing ctx
and an empty array of string to initialize the ScopeManager field:
ctx := &hinter.HintRunnerContext{}
hinter.InitializeScopeManager(ctx, make(map[string]any))
Basically, you have 2 possibilities:
- manually defining the ScopeManager field of
ctx
ctx := &hinter.HintRunnerContext{ ScopeManager: *hinter.DefaultNewScopeManager(), }
- creating an uninitialized
ctx
an callingInitializeScopeManager
, passingctx
and an empty array of string to initialize the ScopeManager field:ctx := &hinter.HintRunnerContext{} hinter.InitializeScopeManager(ctx, make(map[string]any))
Thank you @TAdev0 . I used the Uninitialized ctx option which creates an empty HintRunnerContext first, then initializes the ScopeManager using InitializeScopeManager(). The code now compiles.
LGTM!
@cicr99 should we merge this like this and open another PR to modify every test to be consistent with the default initialized scope manager?
there is a unit test failing after merging the main branch.
This is becasue of UsortVerify
test that uses InitializeScopeManager
to create a scope with positions_dict
. But as we already call InitializeScopeManager
in the general test setting, it wont work.
Can you modify the UsortVerify
so that it calls ctx.ScopeManager.EnterScope
instead?
there is a unit test failing after merging the main branch.
This is becasue of
UsortVerify
test that usesInitializeScopeManager
to create a scope withpositions_dict
. But as we already callInitializeScopeManager
in the general test setting, it wont work.Can you modify the
UsortVerify
so that it callsctx.ScopeManager.EnterScope
instead?
Shouldn't he just call AssignVariable
? Given a default scope exists now?
yes AssignVariable
is enough, you are right. I'll do a PR to update all tests configuration once this one is merged anyway
LGTM!
@cicr99 should we merge this like this and open another PR to modify every test to be consistent with the default initialized scope manager?
I was thinking to do the updating of all tests in this pr as well, but it might take some time and effort, specially with all the merges happening at the moment. I think doing it separately would be the best way to go. Once the tests are passing @fishonamos, we can merge. The PR looks good like this!
I modified "Usort Verify" to just call Assign Variable. I think we need to do for all others too, such as UsortVerifyMultiplicityAssert.
hi @fishonamos , yes i will update all other tests in another PR to make sure we never create unnecessary scopes :)
@fishonamos your unit test dont pass. You should use make build
and make unit
to run tests locally and make sure they pass.
you need to check the return value with AssignVariable
They are now passing
you need to check the return value with AssigneVariable
err = ctx.ScopeManager.AssignVariable("...", ...)
if err != nil {
return err
}
All tests have passed.
lgtm!
well we should probably have used
if err != nil {
t.Fatal(err)
}
in unit tests, but anyway it doesnt matter, and i'm pushing soon a pr that will update this
Modified the code so when the context is created, the Scope Manager is also initialised. This will solve #345