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

Operation is not valid due to the current state of the object #31

Open
bslattz opened this issue Feb 3, 2019 · 1 comment
Open

Operation is not valid due to the current state of the object #31

bslattz opened this issue Feb 3, 2019 · 1 comment

Comments

@bslattz
Copy link

bslattz commented Feb 3, 2019

Problem Statement

There is a problem (bug?) in PQ around re-using function argument names on local variables (immutable though they are) within the function. This is not a problem if you invoke directly, but if you are invoking as a parameter in a host function, the above error is thrown. The problem occurs in...

  • Value.ToText
  • Type.ToText
  • Value.TypeToText

Resolution

All of these have an optional argument signifying recursive types and the same name is recycled in the function body. Simply change the name of the local variable and all is OK.

e.g. in Value.TypeToText change Recurs to _Recurs

let
    Source = (Value as any, optional Recurs as logical) as text =>
    let
        Recurs = if (Recurs<>null) then Recurs else false,
        Type.ToText = #"Load"("Type.ToText"),

        Type = Value.Type(Value),
        ToText = if Value.Is(Value, type type) and Recurs then
            "type " & Type.ToText(Value, Recurs)
        else
            Type.ToText(Type, Recurs),
        Return = ToText
    in Return
in
    Source

To

(Value as any, optional Recurs as logical) as text =>
let
    _Recurs = if (Recurs<>null) then Recurs else false,
    Type.ToText = Load("Type.ToText"),

    Type = Value.Type(Value),
    ToText = if Value.Is(Value, type type) and _Recurs then
        "type " & Type.ToText(Value, _Recurs)
    else
        Type.ToText(Type, _Recurs),
    Return = ToText
in Return

Took me a while to figure this out but, much shorter than writing it myself: thanks for the share!
I won't be using the dynamic loading, but it's the closest I've seen to a build tool in PQ.

@KiaraGrouwstra
Copy link
Owner

looks good! would you mind sending a PR? ditto for the other one.

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