ameliatastic / seahorse-lang

Write Anchor-compatible Solana programs in Python
Apache License 2.0
313 stars 43 forks source link

Possible bug with string type #81

Closed miguel-ot closed 1 year ago

miguel-ot commented 1 year ago

When compiling the code

# Built with Seahorse v0.2.5

from seahorse.prelude import *

declare_id('2U2z3rSoeJYEAkLoStCn676EunGSXXt9HVQCcp7d9PB7')

def mystring() -> str:
  return 'abc'

I obtain the following error message:

✗ Compiling test... Error: anchor build -p test failed:

This is most likely a bug in the Seahorse compiler!

If you want to help the project, you can report this:

Thanks!

Compiling test v0.1.0 (/home/miguel/Aldrin/Programming/Seahorse/test/programs/test) error[E0308]: mismatched types --> programs/test/src/dot/program.rs:10:12 9 pub fn mystring() -> String { ------ expected String because of return type 10 return "abc"; ^^^^^- help: try using a conversion method: .to_string()
expected struct String, found &str

For more information about this error, try rustc --explain E0308. error: could not compile test due to previous error

If I replace return 'abc' with return str('abc'), the code compiles without errors.

ameliatastic commented 1 year ago

Hey Miguel! This is definitely a bug. I'm trying to find a way to fix it, strings are in a very weird state with Seahorse because I had initially only really supported string literals being used in seeds for account inits. I'll keep an eye on this and related problems, have been slowly working on a general solution (see #77)