enso-org / enso

Hybrid visual and textual functional programming.
https://enso.org
Apache License 2.0
7.34k stars 321 forks source link

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

Open radeusgd opened 1 month ago

radeusgd commented 1 month ago

Project containing repro: testproject1.zip

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

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 commented 1 month ago

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.