This issue was raised on Zulip by @rhagenson.
If one imports a package using an alias (use alias = "./path/to/package), this alias is not applied to all symbols imported from the package, as the following code shows:
// This code lives under lib/lib.pony
primitive LibPrimitive
trait LibTrait
fun foo(): LibPrimitive => LibPrimitive
use lib = "./lib"
actor Main is lib.LibTrait
new create(env: Env) => None
This issue also applies if we use interfaces, so it's not unique to using a trait.
The error:
$ ponyc .
Building builtin -> /Users/ryan/.local/share/ponyup/ponyc-release-0.39.1-x86_64-darwin/packages/builtin
Building . -> /Users/ryan/Downloads/test
Building ./lib -> /Users/ryan/Downloads/test/lib
Error:
/Users/ryan/Downloads/test/lib/lib.pony:5:5: can't find declaration of 'LibPrimitive'
LibPrimitive
^
If one implements the foo() method on Main with the applied alias, the code will work correctly. If one looks at the AST, we can verify that the implementation of foo() is copied into the scope of Main without any renaming (diff shows the AST change that should occur for the code to work correctly):
(fun:scope
box
(id foo)
x
x
- (nominal (id $2) (id LibPrimitive) x val x x)
+ (nominal (id $2) (id LibPrimitive) x val x (id lib))
x
- (seq (reference (id LibPrimitive)))
+ (seq (. (reference (id lib)) (id LibPrimitive)))
x
)
Thanks for that nice writeup.
I am collecting some related existing bug reports in the realm of default implementations of traits that give us a picture of the full defects of the current implementation. Might come in handy when starting to work on that:
Most helpful comment
Thanks for that nice writeup.
I am collecting some related existing bug reports in the realm of default implementations of traits that give us a picture of the full defects of the current implementation. Might come in handy when starting to work on that: