Skip to content
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

Importing extension methods ignores hiding and ignores methods imported by name (only all works) #10796

Open
radeusgd opened this issue Aug 12, 2024 · 1 comment
Assignees
Labels

Comments

@radeusgd
Copy link
Member

radeusgd commented Aug 12, 2024

Project containing repro: testproject1.zip

The project above defines a type Typ defined inside of module Typ, and extension methods defined in following modules:

  • in F1 we have Typ.f1 self = 1
  • in F23 we have analogous f2 and f3
  • and in F45 we have f4 and f4.

Then we do the following set of imports:

from Standard.Base import all
from project.Typ import Typ
from project.F1 import all
from project.F23 import all hiding f3
from project.F45 import f4

main = 
    inst = Typ.Value 123

    recover_as_text ~action =
        r = Panic.recover Any action
        r.to_text
    
    IO.println "inst.f1 = "+(recover_as_text inst.f1)
    IO.println "inst.f2 = "+(recover_as_text inst.f2)
    IO.println "inst.f3 = "+(recover_as_text inst.f3)
    IO.println "inst.f4 = "+(recover_as_text inst.f4)
    IO.println "inst.f5 = "+(recover_as_text inst.f5)

Actual behaviour

This yields the following output:

inst.f1 = 1
inst.f2 = 2
inst.f3 = 3
inst.f4 = (Error: (No_Such_Method.Error (Typ.Value 123) UnresolvedSymbol<f4>))
inst.f5 = (Error: (No_Such_Method.Error (Typ.Value 123) UnresolvedSymbol<f5>))

Expected behaviour

Instead, we would expect it to be:

inst.f1 = 1
inst.f2 = 2
inst.f3 = (Error: (No_Such_Method.Error (Typ.Value 123) UnresolvedSymbol<f3>))
inst.f4 = 4
inst.f5 = (Error: (No_Such_Method.Error (Typ.Value 123) UnresolvedSymbol<f5>))

The f3 method should probably not show up because the import is hiding it. But the f4 method is imported by name so it should be available. This is analogous to how we are doing exporting of extension methods - they are exported by the method name (#10274) (even if that may match multiple extension methods for various types). Imports should probably also be consistent with that.

@radeusgd
Copy link
Member Author

I've encountered this problem when I was trying to understand our imports logic when working on the typechecker. I was surprised that ImportExportScope has only typesOnlyNames but it does not have anything to represent the hiding concept.

This issue is partially blocking the typechecker work (#9812) because I need to replicate the logic for creating the runtime ModuleScope but statically. Given that this bug means the logic will change, it is a bit hard to figure out how to replicate the not-yet-implemented logic. I will probably try to approximate it and then will refactor once this bug is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: New
Development

No branches or pull requests

2 participants