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

Sometimes Switches require parens when it seems like they shouldn't #10

Open
skilesare opened this issue Aug 17, 2022 · 1 comment
Open

Comments

@skilesare
Copy link
Collaborator

example:

public func getNFTOwner(metadata: CandyTypes.CandyValue) : Result.Result<Types.Account, Types.OrigynError>
    let val = take Properties.getClassProperty(metadata, Types.metadata.owner), return #err(Types.errors(#owner_not_found, "getNFTOwner - cannot find owner id in metadata", null))
    return #ok(
      switch(val.value){
        case(#Principal(val)){#principal(val)}
        case(#Text(val)){#account_id(val)}
        case(#Class(val)){#extensible(#Class(val))}
        case(#Array(ary))
          switch(ary){
            case(#frozen(items))
              if(items.size() > 0)
                #account(
                  {
                      owner = switch(items[0]){
                        case(#Principal(val)){val }
                        case(_)
                          return #err(Types.errors(#improper_interface, "getNFTOwner -  improper interface, not a principal at 0 ", null))
                      }
                
                      sub_account = if(items.size() > 1)
                          switch(items[1]){
                            case(#Blob(val)){?val  }
                            case(_)
                              return #err(Types.errors(#improper_interface, "getNFTOwner -  improper interface, blob at 1 ", null))
                          }
                      
                        else 
                          null
                  })
              else
                return #err(Types.errors(#improper_interface, "ledger_interface -  improper interface, not enough items " # debug_show(ary), null))

            
            
            case(_){return #err(Types.errors(#improper_interface, "ledger_interface - send payment - improper interface, not frozen " # debug_show(ary), null))  }
          }
        case(_){return #err(Types.errors(#improper_interface, "ledger_interface - send payment - improper interface, not an array " , null))  }
      }
      
    )

The switches need parens or the compile fails

@STRd6
Copy link
Contributor

STRd6 commented Aug 23, 2022

I'm not able to reproduce. This works for me:

module
  public func getNFTOwner(metadata: CandyTypes.CandyValue) : Result.Result<Types.Account, Types.OrigynError>
    let val = take Properties.getClassProperty(metadata, Types.metadata.owner), return #err(Types.errors(#owner_not_found, "getNFTOwner - cannot find owner id in metadata", null))

    return #ok(
      switch val.value {
        case(#Principal(val)){#principal(val)}
        case(#Text(val)){#account_id(val)}
        case(#Class(val)){#extensible(#Class(val))}
        case(#Array(ary))
          switch ary {
            case(#frozen(items))
              if(items.size() > 0)
                #account(
                  {
                      owner = switch items[0] {
                        case(#Principal(val)){val }
                        case(_)
                          return #err(Types.errors(#improper_interface, "getNFTOwner -  improper interface, not a principal at 0 ", null))
                      }

                      sub_account = if(items.size() > 1)
                          switch items[1] {
                            case(#Blob(val)){?val  }
                            case(_)
                              return #err(Types.errors(#improper_interface, "getNFTOwner -  improper interface, blob at 1 ", null))
                          }

                        else
                          null
                  })
              else
                return #err(Types.errors(#improper_interface, "ledger_interface -  improper interface, not enough items " # debug_show(ary), null))



            case(_){return #err(Types.errors(#improper_interface, "ledger_interface - send payment - improper interface, not frozen " # debug_show(ary), null))  }
          }
        case(_){return #err(Types.errors(#improper_interface, "ledger_interface - send payment - improper interface, not an array " , null))  }
      }

    )

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