-
-
Notifications
You must be signed in to change notification settings - Fork 415
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
Aliasing a package import doesn't apply to imported default method implementations #3737
Comments
Thanks for that nice writeup. |
So the issue here seems to be that as stands, we don't consider this case. In scope.c we have the following in if(name != NULL && ast_id(name) == TK_ID) // We have an alias
return set_scope(options, ast, name, package, false);
ast_setflag(ast, AST_FLAG_IMPORT); Note, that AST_FLAG_IMPORT isn't set if we have an alias. Then in import.c, in static bool import_use(pass_opt_t* opt, ast_t* ast)
{
pony_assert(ast != NULL);
if(!ast_checkflag(ast, AST_FLAG_IMPORT))
return true; which means we bail out before any imports because it is an alias. I think we need more sophisticated handling. I'm thinking something like setting a flag for a regular import vs an aliased import. For a regular import, all works as current. For an aliased import, we need to look for anything that is a TK_NOMINAL and if its referenced through an alias, we import into the object in question. @ponylang/committer thoughts? |
@ergl what do you mean by: "If one implements the foo() method on Main with the applied alias, the code will work correctly. " I'm not sure what that code would look like on |
doesnt take into account aliasing from the use when doing:
|
I think this is best handled in:
which currently assumes no aliasing and is creating the basis method that ends up getting copied into the provider. |
Update on that, maybe doing in reify_provides_type is wrong and we want to do in a new method after reification and before adding the method. Not sure. |
@SeanTAllen I meant implementing the function in use lib = "./lib"
actor Main is lib.LibTrait
new create(env: Env) => None
fun foo(): lib.LibPrimitive => lib.LibPrimitive I mentioned that so that I could diff the AST of both versions, which I highlighted in the original comment. |
@ergl Ok, I thought you meant that somehow the default method worked. Which isn't the case. Gotcha. |
I'm working on this with some assistance from @jemc. |
I have a fix for this. I need to clean it up as its two bunches of identical code copied into two locations, I'll have a PR open sometime this week. |
…m default method bodies (#4027) We've had issues with symbols within trait and interface default method bodies. If symbols used within those bodies were not available in the local scope that the method bodies were added to, the symbols couldn't be found. The issue was that we were only searching the local scope. This change adds an additional AST symbol lookup strategy where we look for a function or behavior as our parent. If one exists, we check to see if it was provided by a trait. This is done by looking to see if the AST data is present. If it is, then that is the AST for original trait implementation of the method. We can then use that AST node to find symbols that were present at the original declaration site of the trait. Fixes #3737 Fixes #2150
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 issue also applies if we use interfaces, so it's not unique to using a trait.
The error:
If one implements the
foo()
method onMain
with the applied alias, the code will work correctly. If one looks at the AST, we can verify that the implementation offoo()
is copied into the scope ofMain
without any renaming (diff shows the AST change that should occur for the code to work correctly):The text was updated successfully, but these errors were encountered: