ameliatastic / seahorse-lang

Write Anchor-compatible Solana programs in Python
Apache License 2.0
327 stars 48 forks source link

Error when using `sum` on array of floats #83

Closed mcintyre94 closed 1 year ago

mcintyre94 commented 1 year ago

Example code:

from seahorse.prelude import *

# This is your program's public key and it will update
# automatically when you build the project.
declare_id('FLwzxcGsWo28gVDA7oGHd15sSnmY6kvP8kziJ6gQqCnC')

@instruction
def ix(sig: Signer):
  a = array(1.0, 1.5)
  s = sum(a)
  print(s)

Playground link: https://beta.solpg.io/63b55b8fc6bb8fea17cf0b75

Error:

Building...
   error[E0277]: cannot add `f64` to `{integer}`
 --> /src/dot/program.rs:1:557
  |
1 | ...clone ())) . fold (0 , | accum , elem | accum + elem) ; solana_program :: msg ! ("{}" , s) ; }
  |                                                  ^ no implementation for `{integer} + f64`
  |
  = help: the trait `Add<f64>` is not implemented for `{integer}`

Error seems to be coming from here: https://github.com/ameliatastic/seahorse-lang/blob/e1178ed959246417255321a4cbe5b55431a75994/src/core/compile/builtin/python.rs#L519-L523

This might be tricky to fix because the comment suggests we don't have type info about the array there