ameliatastic / seahorse-lang

Write Anchor-compatible Solana programs in Python
Apache License 2.0
320 stars 46 forks source link

Import ordering bug #88

Closed ameliatastic closed 1 year ago

ameliatastic commented 1 year ago

See thread in Discord.

The general problem is that Seahorse-builtin objects like everything in seahorse.prelude are treated like normal imports. If you have a module that does from seahorse.prelude import *, then you import everything in that module from another module (from my_module import *), then it will carry the prelude names with it. This could cause a bug at compile time, since the compiler didn't know how to handle builtin objects that come from a different module.

We discussed the best solutions in Discord and decided that prelude could just be imported automatically but not exported (like Python builtins), and then still allow other builtins to be re-exported. So there's essentially three cases for imports:

Closes #57

ameliatastic commented 1 year ago

The first commit makes some progress in allowing prelude to be auto-imported + unexported. Still need to resolve how imports work with other modules like seahorse.pyth.

ameliatastic commented 1 year ago

Imports created by the namespace stage are wrapped in a cleaner struct now, which includes information about whether the import references a builtin item or not. This makes it possible for these imports to be pruned out of the generated use statements!

ameliatastic commented 1 year ago

The "stealth fix" is due to a bug that was introduced by the expression context update 😬

Basically the Pyth validate_price_feed method didn't work at all, because it expected a string literal but it was being passed a string.to_string(). Easy fix is to just add the Seed context, which actually lets string literals show up as string literals.